'Could not load file or assembly 'netstandard, Version=2.0.0.0, …'. Reference assemblies should not be loaded for execution

邮差的信 提交于 2019-12-03 10:18:47

The netstandard.dll you are trying to load is a reference assembly that which cannot be loaded for runtime on .NET Framework as pointed out by others. However if you need to resolve that dependency you will need to runtime version that maps to the framework you are trying to run on.

For .NET Standard support we are including them as part of the msbuild extensions that ship with VS so you will want to get the version of netstandard.dll from there. Depending on which version of VS2017 you have installed it should be somewhere like C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\netstandard.dll or from the .NET Core 2.0 SDK you can find it C:\Program Files\dotnet\sdk\2.0.0\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\netstandard.dll

Try using one of those versions in your scenario.

Set Copy Enbale to true in netstandard.dll properties.

  1. Open Solution Explorer and right click on netstandard.dll.
  2. Set Copy Enbale to true.

You can't load a reference assembly.

.NET Standard is a collection of APIs that must be provided by .NET Standard compatible implementations.

A reference assembly only contains contracts. This means that it contains no implementation. The assembly you are trying to load contains the .NET Standard 2.0 contracts.

A contract looks like this: https://github.com/dotnet/standard/blob/master/netstandard/ref/mscorlib.cs

EDIT: .NET Framework 4.7 implements .NET Standard 2.0, so you shouldn't need to load any assembly to use Activator.CreateInstance() to instantiate a .NET Standard type.

NETStandard 2.0.0-preview1 in not compatibility with net461 and net47.

but for realese .NET Core SDK 2.0 assemblies (as well as 2.0.0-preview2)

 var netStandardDllPath = @"c:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\netstandard.dll";
 Console.WriteLine(Assembly.LoadFrom(netStandardDllPath).FullName);

all is ok.

But if you steel need to load preview1 libraries, maybe you should to use netstandard2.0 instead net471.

Wow. I just spent several hours tracking the cause of this "could not load ... netstandard" error down.

For me, the problem was that my .NET Framework project (which references both .NET Framework and .NET Standard libraries) was built with .NET Framework 4.7.2 and the system where I was deploying and running it did not have 4.7.2 installed.

Deploying a very small Console project with the same basic structure and references and executing that in a Command window finally revealed the correct error, in a pop-up, that .NET Framework 4.7.2 was missing.

If you're struggling with this particular error, make sure you have the necessary .NET Framework installed.

Install NetStandard.Library 2.0.0.0 from NuGet , It works for me. when I downgrade .net framework 4.6.1 to 4.6.0

For me solved doing the following: 1 - Installed latest .Net Framework on server. 2 - Updated windows server and my local machine. 3 - Went to Manage Nuget Package and updated all references on the update tab.

Perhaps only doing step 3 can solve in your case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!