MS_Dev
MS_Dev

Reputation: 207

NET core - Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ', .NET 6

I have converted .NET Framework 3.5 TestAPP to .NET 6 TestAPP and worked well. i have an Automation project(C++ project) which was using .NET Framework 3.5 TestAPP.dll to run the tests, but right now i have replaced the .NET Framework 3.5 .dll with .NET 6 TestAPP i.e. TestAPP.dll when i ran the exe in command line , i have got an error as

"Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=6.0.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)"

Please let me know if anything needs to be corrected.

Upvotes: 10

Views: 69597

Answers (11)

JonWillis
JonWillis

Reputation: 3147

This came up on google as the 2nd top result. If using a newer .net framework version, like .Net 8 with older nuget packages it "can" cause issues.

I had this issue with Specflow, it showed in their console output. Specflow is officially deprecated and does not support .net 8. The it stopped with .Net 6 hence the error you can see.

Whilst my issue was Specflow, it could be any nuget package that isn't supported.

You need to install this VS Extension that's in their repo to make it work - https://github.com/SpecFlowOSS/SpecFlow.VS/releases/tag/v2022.1.93-net8

Or move to the new framework that has taken over called Reqnroll.

Upvotes: 0

Rohan Godala
Rohan Godala

Reputation: 71

After updating my solution to .Net 9.0, faced similar issue with Serialization Formatters library when serializing json data to a file using Newtonsoft Json library. Had resolved it by taking explicit reference of latest "System.Runtime.Serialization.Formatters" library in project even though it is not directly used.

Below is the error: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.Serialization.Formatters, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

As per below article, BinaryFormatters have security vulnerabilities because of which "System.Runtime.Serialization.Formatters" library is obselete in .net 9.0 and removed from .Net 9.0 SDK. https://learn.microsoft.com/en-in/dotnet/standard/serialization/binaryformatter-security-guide

From Nuget Manager, if we add this library it downloads 8.0 version itself mentioning it as 9.0

Upvotes: 1

Crab Crab
Crab Crab

Reputation: 1

I fix the similar issue by installing the referenced dlls from NuGet. My case was like: LibraryA needs System.Runtime(6.0.0.) but somehow the dll path
was not correct. I just removed the existing LibraryA references and re-install them from NuGet.

Upvotes: 0

Allan Zeidler
Allan Zeidler

Reputation: 337

It happened after installing .NET 8.0. I think that Microsoft installer uninstalled the .NET 6.0 SDK and installed .NET 8.0 SDK. I don't know why and also don't know why the problem happens... but it was solved...

My solution was install the .NET 6.0 SDK latest version. After that, closed all VS instances and open again. Your project should compile and run normally.

Upvotes: 1

hikers
hikers

Reputation: 31

Try to install .net6 SDK !!! (not .net6 runtime).You can use the 'dotnet --info' to check the dotnet info by windows shell. If it does not contains .net6 SDK, install it. Image

Upvotes: 3

Towhid
Towhid

Reputation: 2084

If you are using .Net versions earlier than .Net 6 and have installed .Net SDK 8 on your machine, this issue may occur. .Net 8 does not support duplicate files in the publish directory. As a result it is failing to load runtime.

Workaround: Install .NET 7 SDK from here (https://dotnet.microsoft.com/en-us/download/dotnet/7.0).

Upvotes: 8

Miroslav Zadravec
Miroslav Zadravec

Reputation: 3730

My solution was to remove all package dependencies and add them again using Nuget package manager. Only then did the project start working again.

Upvotes: 0

Dayán Ruiz
Dayán Ruiz

Reputation: 670

In my case the error was due to worng Default Project in Package Manager Console, if you are running EF migrations or something that is in a project that need to get info from the API make sure you are targetting the right project, also try clean + build first.

Upvotes: 1

Alon S
Alon S

Reputation: 195

When upgrading an app to a later .NET version, edit your csproj file and make sure there is no <RuntimeFrameworkVersion> node in there that someone may have inserted manually. This will not be updated automatically when switching .NET versions

Upvotes: 5

E.Busra
E.Busra

Reputation: 17

The running project returned this error. When I changed it to the way in the image, the error was solved.

Project>Properties

Upvotes: 0

MS_Dev
MS_Dev

Reputation: 207

Resolved the error by changing the C++/CLI properties from visual studio project properties , which was referring to .NET framework earlier and i have changed the property as .NET core runtime(clr:netcore) and it is internally handled all GAC changes and worked well. Hope it might help someone . enter image description here

Upvotes: 7

Related Questions