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

raysefo

Well-known member
Joined
Feb 22, 2019
Messages
362
Programming Experience
10+
Hello guys,

I have a web API that was working without a problem. But today I am getting this error on the production server:

Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, 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)

There is no such problem with the local machine. I tried to update this System.Runtime.CompilerServices.Unsafe but still having the same problem. Any ideas on how to fix it?

Best Regards.
 
Chances are that you actually changed something like updated a Nuget package or two, or had some patches applied to your machine.

See StackOverflow response on how to deal people have dealt with a similar issue when using Redis and its transitive dependencies.
 
Thank you @Skydiver, adding this assembly to web.config solved my issue.

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

thankz solved
C#:
            MySqlConnection connection = null;
            MySqlCommand command = null;
            MySqlTransaction transaction = null;
            string sqlstatement = "";

                connection = new MySqlConnection(WaterWorkDB.GetConnectionStringRemote());
                command = new MySqlCommand();

                connection.Open();

                transaction = connection.BeginTransaction();//Error this but now fixed

                command.Connection = connection;
                command.Transaction = transaction;
XML:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
 
  </startup>

  <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-6.0.0.0" newVersion="6.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>
 
Last edited by a moderator:
@remontesclaros : Other than the bump up to version 6 in your post, how is your solution any different from @raysefo 's solution from 3 years ago?
 
Back
Top Bottom