Failed to load Newtonsoft.json.dll file or assembly.

"Failed to load file or assembly Newtonsoft.Json, Version = 4.0.3.0, Culture = neutral, PublicKeyToken = 30ad4fe6b2a6aeed 'or one of its dependencies. The installed manifest definition for the assembly does not match the assembly reference. (Exception from HRESULT: 0x80131040)."

'The compilation NewtonsoftJson.dll is required for publication on twitter. The version used is 4.0.3.0.

And the same assembly (but diff version 4.0.0.0) is used as a dependent assembly of facebook C # api (dll). However, the assembly above (4.0.3.0) does not work for both cases (i.e., for publishing on twitter and for logging into facebook). To solve it, a separate project was created for publication on twitter and a link to the assembly (4.0.3.0) separately (in the project for writing to Twitter). Another version (4.0.0.0) was added as a link to the main project for facebook but still an error occurs. If the twitter project is disabled and running, then the entrance to facebook works fine and vice-faith.

I did a lot of research and tried the following.

delete temporary asp.net files clean solution restart your computer

I even tried to remove the assembly from gac (however, it is not registered there).

Please help me with this as it does not work. Thanks, S

+8
c # asp.net-mvc winforms
source share
3 answers

It is unclear what the relationship of the projects is or when this error occurs, but here's a hunch.

You have 3 facebook project projects (version 4.0.0.0), a twitter project (version 4.0.3.0), and a main project that references both of these projects. You may be able to build this solution, but at startup, assembly binding will fail. What for? because the default behavior is to copy assemblies locally before running. It happens that the first project is to create copies in bin (say twitter), and then the second project (facebook), and then the main one. However, at the end of this, version 4.0.0.0 is in the seat folder. When you start, as soon as you call something from Twitter trying to use the assembly of problems, the communication failure is due to the fact that it has longer access to the build version 4.0.3.0.

There are several ways around this. One of them registers both assemblies in the GAC. If this cannot be done, go to redirect the assembly binding to your configuration file. Another is to register for the AssemblyResolve event and programmatically download the assembly.

+8
source share

Add the following to the app.config file:

<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> 

in the <configuration></configuration> tags

+8
source share

Install Newtonsoft package in all projects.

 Install-Package Newtonsoft.Json -Version 8.0.3 
0
source share

All Articles