Error in load assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1'
Description
This error happens when I distribute my application. Even when I send the correct dll:
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 it's dependences. The found Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)"
Even sending the correct dll it just doesn't work.
Reproduction Steps
Code error:
Usuario user = new Usuario(); user.Username = "teste"; user.Password = "teste"; user.Role = ".";
string strJson = JsonSerializer.Serialize
Expected behavior
Not error in serialize object
Actual behavior
Error in line serialize.
Regression?
No response
Known Workarounds
No response
Configuration
Net framework 4.8 in Windows 10 (c# Windows Forms)
Other information
No response
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
@paulocarinhena this seems to be impacting .NET Framework, correct? Can you share a repro and file this issue via VS Feedback mechanism? Thanks
I'm getting this but where Version=7.0.0.0 since updating packages to .NET 7 Preview 3 - the issue appears to be with the System.Text.Json package. Downgrading to Preview 2 makes it go away.
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis See info in area-owners.md if you want to be subscribed.
Issue Details
Description
This error happens when I distribute my application. Even when I send the correct dll:
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 it's dependences. The found Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)"
Even sending the correct dll it just doesn't work.
Reproduction Steps
Code error:
Usuario user = new Usuario(); user.Username = "teste"; user.Password = "teste"; user.Role = ".";
string strJson = JsonSerializer.Serialize
Expected behavior
Not error in serialize object
Actual behavior
Error in line serialize.
Regression?
No response
Known Workarounds
No response
Configuration
Net framework 4.8 in Windows 10 (c# Windows Forms)
Other information
No response
| Author: | paulocarinhena |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | - |
This issue has been marked needs-author-action since it may be missing important information. Please refer to our contribution guidelines for tips on how to report issues effectively.
Hi @paulocarinhena could you possibly share a reproducing project (in a zip or a repo) that showcases the issue? Thanks!
This should be fixed by https://github.com/dotnet/runtime/pull/67385
Was that merge in the net7 preview 3 packages released yesterday?
#67385 is not in preview3. It will be in preview4.
That does make preview 3 kind of unusable though 😂
Duplicate of #67385.
@eiriktsarpalis I know this marked as a duplicate but a) I can't respond in #67385, and b) this is still a problem in .NET 7 Preview 4. I've just updated and run my unit tests and all the JSON-based tests are failing with the same exception:
Could not load type 'System.Runtime.CompilerServices.Unsafe' from assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Is this because the Unsafe package is not being published to NuGet, which has no preview versions after .NET 7 Preview 2?

Is this because the Unsafe package is not being published to NuGet, which has no preview versions after .NET 7 Preview 2?
The Unsafe package is not going to be published to NuGet anymore. It is by design. The last stable version of the package is 6.0.0.
Could not load type 'System.Runtime.CompilerServices.Unsafe' from assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
This error means that you are building against 7.0 Preview 3 or newer reference assemblies, but you are running against 7.0 Preview 2 or older runtime. Please make sure to update both the runtime and the reference assemblies to latest Preview.
OK thanks I'll give that ago. Apologies.
This issue has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.
This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.