7

Type Error occurred when creating object: Magento\Framework\Locale\Resolver

when I run this command this error shows. I am using third party theme.

Already tried deleting generated and var/di enter image description here

11
  • check your system.log from var/log/system.log. Here you can find the issue Jun 13, 2019 at 10:30
  • Deleting var/generation, var/cache and var/di and try Jun 13, 2019 at 10:33
  • already done deleting now it stop even showing any error
    – Asad Ullah
    Jun 13, 2019 at 10:34
  • run php bin/magento setup:static-content:deploy -f now it will generate again Jun 13, 2019 at 10:35
  • nothing no result
    – Asad Ullah
    Jun 13, 2019 at 10:37

5 Answers 5

17

The fix for the issue -

Type Error occurred when creating the object: Magento\Framework\Locale\Resolver

is not modifying the core class at all. We need to understand the cause of it first. Modifying the core class is not recommended at all. The issue is not with the class vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php

⚠️ But the issue with the crypt key added to your app/etc/env.php

The reason for this issue is the crypt key is mismatched. You must have taken the database dump from any other instance and trying to run with your current instance. So along with the database, you need to get the crypt key from the same setup where from you got the DB dump.

Just update the crypt key in env.php and it will work fine.

The fix is to use the same pair of crypt keys of the installation from where DB is being used.

Hope it is explained.

Mark me up if was helpful. Happy coding..!!

1
  • 1
    It works if you clear the value in env.php too. Thanks.
    – Ferrmolina
    Jan 25, 2022 at 18:08
7

I have searched around and found this solution this is because of return $plainText SodiumChachaIetf::decrypt() must be of the type string, boolean

Go to this file:

vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php

And Update Below Code:

$plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
            $payload,
            $nonce,
            $nonce,
            $this->key
        );
        if ($plainText == false)
        {
          return "";
        }
        return $plainText;
0

Can you check that you are using the proper crypt key for the database used? Magento's Encryption process will not work if the crypt used for encryption in the database is different than the one declared in the env.php file.

If you have no idea where to get the proper crypt file, you may copy the crypt hash from the magento instance that dumped the database that you are using.

Clear your cache afterwards by deleting them manually.

0

Different key to what was in place when you installed site against what's now in place will cause this issue

Once lost no way to get back

Will only affect handful of extensions that rely on reversible encryption

Magento solution is this

https://magento.stackexchange.com/a/278420/70343

0

I had the same issue and I solved it by adding a typecase when returning the variable.

File: vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php

 /**
 * Decrypt a string
 *
 * @param string $data
 * @return string
 */
public function decrypt(string $data): string
{
    $nonce = mb_substr($data, 0, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, '8bit');
    $payload = mb_substr($data, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, null, '8bit');

    $plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
        $payload,
        $nonce,
        $nonce,
        $this->key
    );

    return (string) $plainText; // <- Add the typecase (string) before the variable
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.