Stackexchange.redis: Error finding System.Runtime.CompilerServices.Unsafe when attempting to create connection

Created on 15 Aug 2019  Â·  7Comments  Â·  Source: StackExchange/StackExchange.Redis

I'm getting this in dotnet core 2.1 (netcoreapp2.1)

Error is:

System.IO.FileLoadException:` Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)
File name: 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Pipelines.Sockets.Unofficial.Arenas.Arena1..ctor(ArenaOptions options, Allocator1 allocator, Int32 blockSizeBytes)
at Pipelines.Sockets.Unofficial.Arenas.Arena1..ctor(ArenaOptions options, Allocator1 allocator) in C:\Code\Pipelines.Sockets.Unofficial\src\Pipelines.Sockets.Unofficial\Arenas\ArenaT.cs:line 144
at StackExchange.Redis.PhysicalConnection..ctor(PhysicalBridge bridge) in C:\projects\stackexchange-redis\src\StackExchange.Redis\PhysicalConnection.cs:line 1536
at StackExchange.Redis.PhysicalBridge.GetConnection(LogProxy log) in C:\projects\stackexchange-redis\src\StackExchange.Redis\PhysicalBridge.cs:line 1117
at StackExchange.Redis.PhysicalBridge.TryConnect(LogProxy log) in C:\projects\stackexchange-redis\src\StackExchange.Redis\PhysicalBridge.cs:line 133
at StackExchange.Redis.ServerEndPoint.CreateBridge(ConnectionType type, LogProxy log) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ServerEndPoint.cs:line 737
at StackExchange.Redis.ServerEndPoint.GetBridge(ConnectionType type, Boolean create, LogProxy log) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ServerEndPoint.cs:line 165
at StackExchange.Redis.ServerEndPoint.Activate(ConnectionType type, LogProxy log) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ServerEndPoint.cs:line 243
at StackExchange.Redis.ConnectionMultiplexer.ActivateAllServers(LogProxy log) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ConnectionMultiplexer.cs:line 1408
at StackExchange.Redis.ConnectionMultiplexer.ReconfigureAsync(Boolean first, Boolean reconfigureAll, LogProxy log, EndPoint blame, String cause, Boolean publishReconfigure, CommandFlags publishReconfigureFlags) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ConnectionMultiplexer.cs:line 1451

I've added the Nuget package System.Runtime.CompilerServices.Unsafe 4.6.0-preview8.19405.3 but it hasn't helped.

Any suggestions?

Most helpful comment

I've put up a blog post on the background, why this happens, and how to fix it at: https://nickcraver.com/blog/2020/02/11/binding-redirects/ (after many issues like this over the years). It's not specific to SE.Redis at all, but that should help get anyone hitting this sorted :)

All 7 comments

Facing the Same Issue.
Have Tried Runtime Binding Redirects but they did not help

This is an issue for me with v4.7.0 of System.Runtime.CompilerServices.Unsafe also. I can build thanks to the binding redirect but the Connect method seems ignore them?

|System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.7.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)
File name: 'System.Runtime.CompilerServices.Unsafe, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileLoadException: 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)
File name: 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Even if I wanted to, I can't install v4.0.4.1 as a package reference to make sure this assembly can be found since if it ever existed it's now unpublished.

Install the 4.7.0 Nuget package for System.Runtime.CompilerServices.Unsafe but in the web.config or app.config enter

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

I guess they didn't keep the file versions up with the package version. I used IL DASM to inspect the .DLL to see what version it was.

This was on a .NET Framework 4.7.2 web app

Just to highlight that we bemoan this topic frequently:
https://twitter.com/Nick_Craver/status/1212401064194068482?s=19 (starts
talking about "unsafe", quickly devolves into a treatise on the broken
assembly loading on netfx)

On Fri, 3 Jan 2020, 16:12 Howard Richards, notifications@github.com wrote:

Install the 4.7.0 Nuget package for System.Runtime.CompilerServices.Unsafe
but in the web.config or app.config enter

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

I guess they didn't keep the file versions up with the package version. I
used IL DASM
https://docs.microsoft.com/en-us/dotnet/standard/assembly/view-contents
to inspect the .DLL to see what version it was.

This was on a .NET Framework 4.7.2 web app

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/StackExchange/StackExchange.Redis/issues/1207?email_source=notifications&email_token=AAAEHMDBI3MMLGMYBW567QLQ35PYPA5CNFSM4IL5LLR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIBPD2A#issuecomment-570618344,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAEHMEJTDALRRONQ7TR2P3Q35PYPANCNFSM4IL5LLRQ
.

I've put up a blog post on the background, why this happens, and how to fix it at: https://nickcraver.com/blog/2020/02/11/binding-redirects/ (after many issues like this over the years). It's not specific to SE.Redis at all, but that should help get anyone hitting this sorted :)

I'm using netcore2.1 webapi , stackexchange 2.2.4(also tried 2.0.513) still get this error, dont now how to solve this.

I've put up a blog post on the background, why this happens, and how to fix it at: https://nickcraver.com/blog/2020/02/11/binding-redirects/ (after many issues like this over the years). It's not specific to SE.Redis at all, but that should help get anyone hitting this sorted :)

That blog article mentions fixes for .net framework. I'm on .net core 2.2 and having an issue with this assembly. But I get a very generic message that doesn't mention the version number it's looking for, so I'm not sure what to do. Any pointers?

EDIT
I just added the System.Runtime.CompilerServices.Unsafe v5.0.0 package in this same project and it resolved my issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ConnorL33t picture ConnorL33t  Â·  165Comments

swapnashinde picture swapnashinde  Â·  34Comments

Iamcerba picture Iamcerba  Â·  24Comments

CDargis picture CDargis  Â·  41Comments

BenedicteLeo picture BenedicteLeo  Â·  18Comments