My Windows service is in the same solution as a MVC project.
The MVC project uses a reference to SignalR Client which requires Newtonsoft.Json v6 +
the Windows service uses System.Net.Http.Formatting, which requires Newtonsoft.Json version 4.5.0.0.
I assumed this would not be a problem, as I could just use a binding redirect in my App.Config, however I get an error of
An unhandled exception of type 'System.IO.FileLoadException' occurred
in System.Net.Http.Formatting.dll
Additional information: Could not load file or assembly
'Newtonsoft.Json, Version=4.5.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)
my app.config has the following:
<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 added that myself, and it does not work, I have also tried uninstalling and re-installing Json.Net with the nuget package manager, to no avail
We faced same error and struggled to fix for few days. We finally we found this post on stack overflow Assembly reference cannot be resolved - dependentAssembly issue?
This made us realize to look into the version of System.Net.Http.Formatting being used and we found that our solution had been using multiple version of System.Net.Http.Formatting.dll and those each of them were referencing different version of Newtonsoft.Json.dll.
Removing references of older version of System.Net.Http.Formatting and adding references back, fixed the problem.
Hope that helps.
Does the assemblyBinding tag have proper xmlns schema? Check if the issue you are encountering is same as Assembly binding redirect does not work
#chintan123 actually pointed my in the right direction, turns out that despite the class library I was creating had a reference to both System.Net.Http.Formatting and also Newtonsoft.Json, only the former was being copied to the bin directory of the calling project that needed it.
Adding a reference to Newtonsoft.Json to the main calling project fixed the issue.
Related
I am getting this error whenever I try and run a webjob project with application insight and entity framework.
System.IO.FileLoadException: 'Could not load file or assembly
'System.Runtime.InteropServices.RuntimeInformation, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)'
I have installed the following nuget packages
Microsoft.Azure.WebJobs.Logging.ApplicationInsights version 2.1.0-beta4
Microsoft.Extensions.Logging version 2.0.0
Microsoft.Extensions.Logging.Console version 2.0.0.
This all works with a new Visual studio 2017 webjob project, its when I try and include an existing code base, primarily using entity framework that I get this error. When I look at the reference in the one that works I don't have the System.Runtime.InteropServices.RuntimeInformation, yet it has been added to the project with entity framework. It seems to be part of .net standard, but how come I don't need .net standard for my new console app!
I'm not sure why its looking for Version 0.0.0.0 either as the one I have is 4.0.2.0
I have also tried adding this to the project file but this didn't work.
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Any help would be greatly appreciated
Many thanks
Confirming the comment made above by dwilliss also worked for me. The solution was to get rid of:
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
(In my case from the app.config, for a Windows Service.) My project has an indirect dependency to System.Runtime.InteropServices.RuntimeInformation only. It is a dependency of a NuGet package I imported.
Could you be missing the loaded assembly from your configuration file? Ensure you have something similar to the following within your web.config. NuGet would normally do this but maybe it hasn't and it doesn't know what to load in
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
If you have updated a project's .NET runtime version from a version before 4.7.1 to 4.7.1 or later then uninstall the Nuget package, delete / comment out the App.config part if it remains, and re-add the reference from the framework. It is in the framework from 4.7.1 onward, before that you had to add a Nuget package.
[edit]... as per Michael's comment above that I upvoted before living memory.
Yeah!
Thanks to https://stackoverflow.com/a/52785620/8081796
The fix is pretty simple:
edit the app.config file and on the node "dependentAssembly"
where name attribute is
"System.Runtime.InteropServices.RuntimeInformation", just remove
the publicKeyToken attribute.
Good Luck
This type of an error sometimes also occurs when you add a project reference from some different platform and try to build it. Remove the references and that should work.
I am working on integrating Google Cloud PubSub into my c# project, I used NuGet to install 1.0.0-beta11, no errors at all. When I run my project and when it reaches the code that uses pubsub, I get the following error:
An unhandled exception of type 'System.IO.FileLoadException' occurred in
Google.Api.Gax.dll
Additional information: Could not load file or assembly 'Google.Apis.Auth, Version=1.21.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
NuGet did install all the dependencies including Google.Apis.Auth.dll, but it's 1.27.1. I have tried everything I could think of, including grabbing 1.21.0 of that dll and using that, but no success. I have been able to run the .net sample just fine with no error.
Any thoughts? Let me know if you need more info
Okay, I've found the reference to Google.Apis.Auth 1.21.0 - it's in the Grpc.Auth NuGet package.
If you just add a reference to the Grpc.Auth DLL, you'll get this kind of failure - but if you manage all the dependencies via NuGet, I'd expect it to be okay - it should add assembly binding redirects for you.
Without knowing your exact setup, it's quite tricky to say more than that - it could be that your library needs assembly binding redirects, but the application is in control of them... and in particular, if your application only has a reference to the library DLL, that would cause the problem.
As a workaround, you could either manually add the assembly binding redirects (the exact way of doing that will depend on the application type) or just add a reference to Google.Cloud.PubSub.V1 in the application as well as the library, at which point NuGet will do all the dependency handling for you.
You can append the following to your app.config file.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Google.Apis.Auth" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
<bindingRedirect oldVersion="1.21.0.0-1.35.1.0" newVersion="1.35.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Old issue but maybe will help someone in the future.
Was stuck with it also, it's indeed the bindingRedirect issue.
In my case it was that the app.config was at the wrong level, just at the project level.
Good luck
I am having problems running my web application.
The project setup is ASP.NET Core web application (.NET Framework). I don't seem to get any Build error. The project doesn't just run.
System.IO.FileLoadException: 'Could not load file or assembly 'Microsoft.Win32.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
Try adding the System.Net.Http nuget package.
This happened to me after I had updated to Visual Studio 2017 15.4.5 and also updated a load of Nuget packages. I think part of the problem is also using .net framework 4.7.1 as well, which I installed last week...
The fix for me was to remove the dependent assembly from web.config, so just comment out or delete this section:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Win32.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
In other for me to get it working i uninstalled the Microsoft.Win32.Primitives then installed the exact version which is 4.0. this worked fir me.
Note that there are higher versions but they did not work for me.
I accidently deleted my *.suo files and the problem fixed itself. Maybe it was an accident, or irrelevant but i just thought to share it.
If you are targeting .Net 4.7.1 project, I contend that a 4.7.1 versioned Primitives DLL is not available. Take a look at the properties in Nuget
I believe the Nuget expression would need a > not a = 4.6.
This feels like a hack, but it seemed to work. If you open Web.config, change this to 4.6
I am setting up the API for my MVC-4 app and when I uncommented this line in Globals.asax.cs:
WebApiConfig.Register(GlobalConfiguration.Configuration);
I received this exception when I started my project back up:
An exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll but was not handled in user code
Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.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)
What should I do?
Update 1 (screenshots)
from what I can tell, JSON.Net looks like it is installed correctly.
Update 2
JSON.Net actually seems to work when the API routes are commented out in Globals.Asax. This doesn't throw any errors:
public ActionResult Index()
{
var foo = Newtonsoft.Json.JsonSerializer.Create();
return View();
}
Visual Studio only complains when this line is uncommented:
WebApiConfig.Register(GlobalConfiguration.Configuration);
This also occured to me today. Seems like there had been an update for json.net (now version 6.0.3), causing nuget to download the latest version after build. However references to old json.net libs might not get updated when there are depencies to other libs.
Solution: Manually open the manage nuget packages for solution window and uninstall old version(s) of json.net. Then take the latest version and install for all needed projects. That fixed the exact error you had for me...
-- edit --
Ok, so I found out that this solution worked for me locally, but remotely this did not solve my issues. Seems like there are some old dependencies from other libs hard referencing the 4.5.0.0 version of json.net. More topics on Stackoverflow.com provide the following solution.
Add this assembly binding redirect to your web.config file:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-4.5.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Most probably Newtonsoft.Json DLL is not properly deployed.
Make sure you have the Newtonsoft.Json DLL in your (IIS / project) bin folder.
Alternatively, you can also install that DLL to GAC if you plan to use it across multiple projects.
It looks like that you don't have Newtonsoft.Json installed/referenced. Web API relies on this and won't work correctly until you resolve this dependency. You can install it via NuGet.
Simply delete your Newtonsoft.Json dll from bin folder then open package.config file and remove your Newtonsoft.Json entry from there then reinstalled your Newtonsoft.Json by command but don't installed newer version if you face this problem with newer version find old version command
like Install-Package Newtonsoft.Json -Version 6.0.8
now Install-Package Newtonsoft.Json -Version 7.0.1 is also aviable but i suggest to you installed 6.0.8 version its working
After signing the third parties assemblies and adding them to GAC I am getting the below error: also the Assembly Binder Log Entry shows this error
It says mismatching assemblies not sure how mistnaching as I deleted all obj and bin fold and batch built the application + reimported the dlls.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\WebDev.WebServer40.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = AKBARCA\user
LOG: DisplayName = ClubStarterKit.Core, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase =
file:///C:/Users/user/Desktop/NhibernateMediumTrust/NhibernateMediumUpgrade/direct/clubstar
terkit v3 preview/ClubStarterKit.Web/
LOG: DEVPATH = C:\ProgramData\Red Gate\.NET Reflector\DevPath
LOG: Initial PrivatePath =
C:\Users\user\Desktop\NhibernateMediumTrust\NhibernateMediumUpgrade\direct\clubstarterkit v3 preview\ClubStarterKit.Web\bin
Calling assembly : ClubStarterKit.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
From my experience, this happens, usually once you've published your app and when you have different versions of nuget packages in play. If this happens to be your situation as well, the best way I've found to fix it is to right-click the solution (not the individual projects) and choose "Manage Nuget Packages". Then, locate the offending assembly in the installed packages. You'll probably see it listed multiple times. Click "Manage" on each of the older versions of the package and uncheck all your projects. Once only the latest version of the package remains in the list. Click "Manage" on this one and recheck any projects that need the package. This will essentially upgrade them all to use the same version of the package and should resolve your mismatch error.
I faced similar problem. In my case, I was having multiple projects in my solution.
One of the project was referring EntityFramework 4.0 and that project was being referred in another project that was referring to EntityFramework 5.0. I brought them in sync and the problem got away.
Hum...
I faced something similar with the same error message.
In my case I've updated manually the version of the assemblies.
In the referenced assembly I had another version...
So, I updated it in the web.config.
This solved my problem.
Your === Pre-bind state information === seems incomplete.
Generally it shows the execution and the last line shows the error, so, we can help only sharing our experiences.
Example:
I hope someone else facing this problem find this helpful.
In my case, the error happens when the version specified in web.config's <bindingRedirect> of the dependent assembly (e.g. Newtonsoft.Json) doesn't match the version that is actually in the bin folder. Once the version number in the web.config is updated, the problem is fixed.
When I experienced this problem in the past, I deleted all my project's dll's from the gac, rebuilt the solution, then did iisreset and it was solved.
One way to solve this could be, going under "Manage NuGet Packages for Solution" by doing right click in the solution explorer.
Once there, go to "Consolidate" and find the package that is causing the problems. Make sure that all the projects within the solution are using the same version.
I had a different cause: in my case, I had used various nuget package versions previously, and I had an app.config which for some reason had been automatically generated with this kind of content:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
</dependentAssembly>
So I only had Version 1.1.0.0 installed, but because of this redirect instruction, it looked for 1.1.1.0 even though Visual Studio had the nuget for 1.1.0.0 installed. Changing the newVersion to 1.1.0.0 fixed everything:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.0.0" />
</dependentAssembly>
I got this error using FASTjson:
_jsonConfig = fastJSON.JSON.ToObject<jsonConfig>(jsonConfigFileContents);
It failed on this line:
Type t = Type.GetType(typename);
Which causes an exception in System.RuntimeTypeHandle.GetTypeByName
The problem was a difference in the JSON file compared to the JSON Object Model.
The solution is to re-save the JSON Object Model to file, eg:
string jsonSettings = fastJSON.JSON.ToJSON(JSONObjectModel);
File.WriteAllText(JSONFilePath, jsonSettings);