Could Not Load File or Assembly System.Runtime.Compilerservices.Unsafe

Could not load file or assembly System.Runtime.CompilerServices.Unsafe

Could not load file or assembly System.Runtime.CompilerServices.Unsafe

It seems that you have installed System.Runtime.CompilerServices.Unsafe nuget package 4.5.3 version. And it corresponds to System.Runtime.CompilerServices.Unsafe.dll assembly version 4.0.4.1.

Suggestion

1) Please try to register System.Runtime.CompilerServices.Unsafe version 4.0.4.1 into GAC so that the system can it.

  • Run Developer Command Prompt for VS2019 as Administrator

  • type:

    cd xxxxx (the path of the the System.Runtime.CompilerServices.Unsafe 4.0.4.1)

    gacutil /i System.Runtime.CompilerServices.Unsafe.dll

2) If you use Net Framework projects with xxx.config file, you could use bindingRedirect.

Add these in app.config file or web.config file:

<configuration>  
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe"
publicKeyToken="b03f5f7f11d50a3a"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1"
newVersion="4.0.4.1"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Besides, if you update System.Runtime.CompilerServices.Unsafe nuget package version to the newer version, you should also changed the bindingRedirect assembly version.

You can refer to these assembly versions of System.Runtime.CompilerServices.Unsafe

4.5.x is System.Runtime.CompilerServices.Unsafe nuget package version while 4.0.x.x is System.Runtime.CompilerServices.Unsafe.dll assembly version.

4.5.0 is 4.0.4.0 
4.5.1 is 4.0.4.0
4.5.2 is 4.0.4.0
4.5.3 is 4.0.4.1
4.6.0 is 4.0.5.0
4.7.0 is 4.0.6.0
4.7.1 is 4.0.6.1
5.0.0 is 5.0.0.0

Could not load file or assembly System.Runtime.CompilerServices.Unsafe on a clean autofac.mv5 installation

You probably have another library that uses a different version of System.Runtime.CompilerServices.Unsafe. What's in web.config?

Did you tried bindingRedirect?

<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>

If you have a newer version replace it in the newVersion above.

VS2017 crashes with 'FileNotFoundEx: System.Runtime.CompilerServices.Unsafe, V=4.0.4.1' upon loading any project

Sorry it took so long. Was under a gun to finish a project..

The root cause of the problem turned out to be ICSharpCode.CodeConverter v.8.4.1.0!

Wow, of all the pieces installed (which aren't that many)..

On a hunch (since the problem was local to Visual Studio) I started looking at Tools and Extensions, and noticed on this component the Date Installed being past the most recent Windows Update! The Automatically update this extension checkbox was checked (by default?).

So it must have silently updated upon VS restart?!

Granted, updates are useful and sometimes necessary. But they also may introduce problems. Performing updates automatically is one thing. But not informing the user about it is bad!


Here's an excerpt from the C:\TEMP\VSIXInstaller_f0335270-1a19-4b71-b74b-e50511bcd107.log:

Initializing Uninstall...
Extension Details...
Identifier : 7e2a69d6-193b-4cdf-878d-3370d5931942
Name : Code Converter (VB - C#)
Author : IC#Code
Version : 8.4.1.0
Description : Convert VB.NET to C# and vice versa with this roslyn based converter
Locale : en-US
MoreInfoURL : https://github.com/icsharpcode/CodeConverter
InstalledByMSI : False
SupportedFrameworkVersionRange : [4.6,)

Supported Products :
Microsoft.VisualStudio.Community
Version : [15.0,17.0)
Microsoft.VisualStudio.Community
Version : [17.0,18.0)

References :
Prerequisites :
-------------------------------------------------------
Identifier : Microsoft.VisualStudio.Component.CoreEditor
Name : Visual Studio core editor
Version : [15.0.26004.1,)

As soon as I removed this, VStudio was able to open/load projects; no restart was needed! Before it would crash even initializing/opening a new empty ones!

While reading the documentation on this converter I also found a very similar bug.



Related Topics



Leave a reply



Submit