System.IO,FileLoadException Error when application runs - c#

I am having a very odd issue. I have done some research online in regards to this but none of the answers seem to help. This application was compiling and running properly a couple days ago, now it just errors out with the following error. Any suggestions on what I can do to resolve the issue? I really don't know where to go from here.
System.IO.FileLoadException: Could not load file or assembly
'Newtonsoft.Json, Version=4.0.5.0, Culture=neutral,
PublicKeyToken=xxxxx' or one of its dependencies. The located
assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040) File name: 'Newtonsoft.Json,
Version=4.0.5.0, Culture=neutral, PublicKeyToken=xxxxx'

My next steps would be to do the following:
Remove this in all projects using NuGet.
Go into the NuGet package repository and delete the files for Newtonsoft.Json. (they shouldn't still be there but if they are, it indicates a problem with NuGet and more troubleshooting there is required - in my experience, NuGet works about 30% of the time, and the rest of the time it is a pain in the ass).
Manually delete all the bin and obj folders in your project(s).
Re-add the Json library via NuGet.
If that doesn't work, please tell that as well.

Related

Microsoft.Bcl.Async trying to load System.Threading.Tasks 1.5.11.0

I've added Microsoft.Bcl.Build/Microsoft.Bcl and Microsoft.Bcl.Async to some projects in my solution where I want to use async/await.
Everything works fine on my machine with .Net4.5 installed. However, when I start the application on a machine with only .Net4 installed, at some point, the application crashes with the following Exception:
Could not load file or assembly 'System.Threading.Tasks, Version=1.5.11.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)
Looking at the StackTrace, the exception seems to be generated in a third party library that we reference.
When I analyze the Microsoft.Threading.Tasks.dll provided by Microsoft.Bcl.Async, I see that it does reference System.Threading.Tasks Version 1.5.11.0, but version 2.6.10.0 is included in Microsoft.Bcl.
Am I doing something wrong?
I found the solution! It was actually very simple. I just had to copy and paste the binding redirects that nuget adds in the app.config files into the *.exe.config file. Then it just magically works. Easy fix.

RazorEngine - Windows 10 Anniversary update 1607 - Could not load file or assembly System.Web.Razor

I am using RazorEngine in one of our applications and it was working fine until Windows 10 Anniversary. On machines with this update, RazorEngine stopped working and I am stuck with this error: Could not load file or assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Has anyone here encountered this?
Note: This question is also posted here: https://github.com/Antaris/RazorEngine/issues/450
One thing that comes to mind that may help is that if the 'System.Web.Razor' assembly was being read from the GAC rather than being copied directly to the bin folder of your application when built and for some reason the Windows 10 Anniversary update removes / updates this assembly from the GAC it could cause this issue.
Figured out the problem. There are 2 different RazorEngine.dll files included with the package, one for 4.0 and one for 4.5. They are identical in size and report the same version number. I inadvertently copied the one for 4.0 which was looking from the older System.Web.Razor DLL version.

VS 2015 suddenly complaining about Newtonsoft.Json version compatibility

I have a complex solution which suddenly -- and I mean suddenly, for days it was compiling just fine and the next moment it wasn't -- started complaining about Newtonsoft version compatibilities:
Severity Code Description Project File Line Suppression State
Error CS1705 Assembly 'UploadFramework' with identity
'UploadFramework, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' uses 'Newtonsoft.Json, Version=9.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' which has a higher
version than referenced assembly 'Newtonsoft.Json' with identity
'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' UploadProcessor..NET Framework
4.6 C:\Programming\ConnellCampaigns\src\UploadProcessor\batch\EnvelopeSalutationJob.cs 341 Active
I am totally at a loss as to how to fix this...as so far as I can tell, nothing has changed in the code base.
However, I had just done a "reorganize usings" across the entire solution, which modified quite a few files. OTOH, as soon as I ran into this problem, I immediately reverted all the changes -- thank goodness for git! -- so I should be back to where I am.
But I'm not...
Any advice on how to fix this would be greatly appreciated.
Additional Info
I should've mentioned that the project.json file for UploadFramework has this line in it:
"Newtonsoft.Json": "6.0.8"
There's a blue squiggly line under the 6.0.8 which, when you hover the mouse over it, says that the project ended up with version 9.0.1. I don't understand how I can specifically define a particular version, and end up with a more recent one. Perhaps that's a clue as to what's going on.
You have two different versions of the Newtonsoft assembly references in your solution. You can use the "consolidate" option in the nuget package manager and you should be fine.
If it do not work after a revert: clean is the first thing to try, sometimes you also need to clean up the /packages folder - you might have multiple folder for Newtonsoft these. Simply delete the version you are not working. Then the solution should build again.

Referenced assembly 'GenCode128.dll' is not a valid assembly

I am now dealing with a existing solution in VS2012.
Now I can execute it in debug mode but cannot trigger some of the function with the error
"Exceptions: System.Exception: Could not load file or assembly
'Interop.Score, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=5ce8a8a190705d24' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)"
After finding some of the suggestion, some of that suggest me to compile the solution in 32-bit (x86).
However, when I tried to rebuild with the target platform x86, another type of error occur and I even cannot run in debug mode, the error:
Referenced assembly 'GenCode128.dll' is not a valid assembly C#
P.S. GenCode128.dll is one of the error .dll, there is at least 2 of this kind of error.
I cannot search any successful way to solve this problem, appreciate for any help.
You can use a decompiler such as DotPeek (https://www.jetbrains.com/decompiler) to look inside your DLL and see if it is a valid .NET DLL -- and which version of .NET it is. It could be an x64-compiled assembly; in that case you cannot use it on a 32-bit system or from a 32-bit-compiled .NET assembly.
You can try installing it from NuGet.
I've created a NuGet package for GenCode128.dll here: https://www.nuget.org/packages/GenCode128/
Also the source can be found in GitHub: https://github.com/SourceCodeBackup/GenCode128

Compile EntityFramework 6

I found a problem within Entity Framework. I downloaded the code and fixed the issue, and finally compiled the assemblies.
Now i have been struggling for hours but I can't figure out HOW to use my assemblies in my project. I tried to overwrite the assembly in the packages folder but whenever I try to execute commands from the package manager I get errors like
"Unable to load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one .... The assembly's manifest definition does not match the assembly reference. (Eccezione da HRESULT: 0x80131040)".
The same happens when running my project.
EDIT:
I tried also to find and replace any revelant (not all) occurrences of Microsoft PublicKeyToken in EntityFramework.dll, EntityFramework.PowerShell.dll and replace them in packages folder. Nothing. Tried to modify any references in .csproj, app.config. nothing.
How can I solve the problem and use my EntityFramework.dll both in project and Package Manager?
Thanks

Categories