runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Error in load assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1'

Open paulocarinhena opened this issue 4 years ago • 16 comments

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(user); <= Error

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

paulocarinhena avatar Apr 14 '22 13:04 paulocarinhena

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.

ghost avatar Apr 14 '22 13:04 ghost

@paulocarinhena this seems to be impacting .NET Framework, correct? Can you share a repro and file this issue via VS Feedback mechanism? Thanks

jeffschwMSFT avatar Apr 14 '22 15:04 jeffschwMSFT

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.

bfren avatar Apr 14 '22 16:04 bfren

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(user); <= Error

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:

area-System.Text.Json, untriaged

Milestone: -

ghost avatar Apr 14 '22 16:04 ghost

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.

ghost avatar Apr 14 '22 17:04 ghost

Hi @paulocarinhena could you possibly share a reproducing project (in a zip or a repo) that showcases the issue? Thanks!

eiriktsarpalis avatar Apr 14 '22 17:04 eiriktsarpalis

This should be fixed by https://github.com/dotnet/runtime/pull/67385

jkotas avatar Apr 14 '22 18:04 jkotas

Was that merge in the net7 preview 3 packages released yesterday?

bfren avatar Apr 14 '22 20:04 bfren

#67385 is not in preview3. It will be in preview4.

jkotas avatar Apr 14 '22 20:04 jkotas

That does make preview 3 kind of unusable though 😂

bfren avatar Apr 14 '22 21:04 bfren

Duplicate of #67385.

eiriktsarpalis avatar Apr 15 '22 09:04 eiriktsarpalis

@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?

Screenshot 2022-05-11 072554

bfren avatar May 11 '22 06:05 bfren

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.

jkotas avatar May 11 '22 15:05 jkotas

OK thanks I'll give that ago. Apologies.

bfren avatar May 11 '22 19:05 bfren

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.

ghost avatar May 26 '22 21:05 ghost

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.

ghost avatar Jun 10 '22 00:06 ghost