C# - "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 system cannot find the file specified."

200 views
Skip to first unread message

Csaba Szigeti

unread,
Mar 7, 2024, 8:54:20 AMMar 7
to Protocol Buffers
Hello,

  We have a dll for Windows which is written in C# which depends on the Google.Protobuf nuget package.

  Previously we compiled our dll using .Net Framework 3.5 and Google.Protobuf 3.6.1 . This older version didn't have the System.Runtime.CompilerServices.Unsafe.dll dependency. We didn't have any issues with it.

  We updated our dll to use .Net Framework 4.5.0 and Google.Protobuf 3.21.4. This new version bring in mutliple dependencies : 
System.Buffers.dll, System.Memory.dll, System.Runtime.CompilerServices.Unsafe.dll.
  We are deploying these dependencies next to our dll.
  Using this new setup some of our customers have the following issue when they try to call a function from our dll : 
"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 system cannot find the file specified."

Concrete 
steps to reproduce the behavior:
  1. Build a dll, which is using Google.Protobuf 3.21.4. Make sure that all the dependencies are deployed next to the dll :
    System.Buffers.dll, System.Memory.dll, System.Runtime.CompilerServices.Unsafe.dll
  2. Open Powershell
  3. Call Add-Type -Path ./mydll.dll
  4. Call a function, from the dll, which is using protobuf

What did you expect to see
No issues, the function should work without issues on all machines.

What did you see instead?
The following error was reported on SOME machines :
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 system cannot find the file specified.

We are not sure what is causing this to happen only on some machines. We don't have access to these machines and we weren't able to reproduce the issue. Using Procmon we see that the System.Runtime.CompilerServices.Unsafe.dll was not tried to be loaded from the path to which we deployed it :
not_working.png


  Do any of you know what could cause this to happen ONLY ON SOME MACHINES?

  We have only been able to reproduce the issue by modifying the global assembly registry (using 
gacutil), but that is not necessarily reproducing the exact same issue like some of our customers are seeing...

Thank you for your help in advance,
Csaba Szigeti
Reply all
Reply to author
Forward
0 new messages