Newtonsoft.Json (FileLoadException)

0

I installed sendgrid package from azure.

I created those two functions: (I am using web api technology in a webform solution).

    [HttpGet]
    public  void SendEmail()
    {//http://localhost:64270/api/Test/SendEmail

         SendAsync().Wait();
    }

        private async Task SendAsync()
    {
        var apiKey = MailProjectSettings.apiKeyFullAccess;

        var client = new SendGridClient(apiKey);
        var msg = new SendGridMessage();

        msg.SetFrom(new EmailAddress("tech@p.com", "Pentester "));


        var recipients = new List<EmailAddress>
        {
            new EmailAddress("pen775@gmail.com", "Jeff Smith")
        };

        msg.AddTos(recipients);

        msg.SetSubject("Testing the SendGrid C# Library");

        msg.AddContent(MimeType.Text, "Hello World plain text!");
        msg.AddContent(MimeType.Html, "<p>Hello World!</p>");

        msg.SetFooterSetting(
                 true,
                 "Event Name",
                 "<strong>Event Name</strong>");



        var response = await client.SendEmailAsync(msg);


    }

On this line of code:

 SendAsync().Wait();

I get this:

FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I tried to search for a solution and every solution produced the same error.

The sendgrid requires a dependency that newtonsoft is version 9.

Here what I have in my web config.

    <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
  </dependentAssembly>

I executed this:

uninstall-package newtonsoft.json -force

and then:

install-package newtonsoft.json

I got the same nodes added in the web config.

What else can I do to prevent that error from happening?

UPDATE:

PM> install-package newtonsoft.json

Attempting to gather dependency information for package 'newtonsoft.json.11.0.2' with respect to project 'CRM', targeting '.NETFramework,Version=v4.6.1' Gathering dependency information took 5.5 sec Attempting to resolve dependencies for package 'newtonsoft.json.11.0.2' with DependencyBehavior 'Lowest' One or more unresolved package dependency constraints detected in the existing packages.config file. All dependency constraints must be resolved to add or update packages. If these packages are being updated this message may be ignored, if not the following error(s) may be blocking the current package operation: 'Microsoft.AspNet.WebApi.Client 5.2.6 constraint: Newtonsoft.Json (>= 6.0.4)', 'Microsoft.IdentityModel.Tokens 5.1.5 constraint: Newtonsoft.Json (>= 9.0.1)', 'Microsoft.Owin.Security.OAuth 4.0.0 constraint: Newtonsoft.Json (>= 9.0.1)', 'Sendgrid 9.9.0 constraint: Newtonsoft.Json (>= 9.0.1)', 'WebGrease 1.6.0 constraint: Newtonsoft.Json (>= 5.0.4)' Resolving dependency information took 0 ms Resolving actions to install package 'newtonsoft.json.11.0.2' Resolved actions to install package 'newtonsoft.json.11.0.2' Retrieving package 'Newtonsoft.Json 11.0.2' from 'nuget.org'. Adding package 'Newtonsoft.Json.11.0.2' to folder 'B:\OGSWallet\OGSWallet\packages' Added package 'Newtonsoft.Json.11.0.2' to folder 'B:\OGSWallet\OGSWallet\packages' Added package 'Newtonsoft.Json.11.0.2' to 'packages.config' Successfully installed 'Newtonsoft.Json 11.0.2' to CRM Executing nuget actions took 3.45 sec Time Elapsed: 00:00:09.9033493

I get this error if I try to modify the binding node to this: from this:

Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Nuget says that I have 11.02 version installed.

I also tried to add the dll manually to my project references.

c#
asp.net
json.net
sendgrid
asked on Stack Overflow Jun 19, 2018 by dan mann • edited Jun 19, 2018 by dan mann

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0