Paul Michaels
Paul Michaels

Reputation: 16685

Error referencing Net Standard from Net 4.6.1 / 4.7

I have a web app initially targeting 4.6.1. This web app references a class library; in turn, this references a Net Standard 1.6 class library.

Adding the reference to the Net Standard library was the latest change, and appears to have caused it to break: the web app was working fine until the Net Standard library was introduced; at which point, I started getting the error:

Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

System.Runtime is included as a NuGet package in the web app.

It may not be relevant, but when I look in the packages directory; I see System.Runtime.4.3.0\lib has net45 and net462 directories, but not 4.6.1 or 4.7 (see below for why I would expect this).

Some things that I've tried that haven't worked:

There's enough recent stuff on the web that makes me think I'm not the only person to experience this; although I haven't found any explanation as to what might be the cause. Can anyone offer an explanation as to what might be causing this, or any diagnostic steps that I can use?

Upvotes: 11

Views: 1871

Answers (4)

Lavinia N.
Lavinia N.

Reputation: 246

I had a similar problem and I solved it by removing the System.Runtime reference from the project and install it via Nuget (Net Standard compatible). It wasn't the only package that had problems (other example, System.Net.Http). Also, if you have multiple projects in your solution, you should install Net Standard on every one of them.

Upvotes: 3

lvoros
lvoros

Reputation: 312

After a long converting process, which I described here I have the experience: you have to install the NuGet package NETStandard.Library also in your main project (in your webapp .net 4.6.1). It will install a plenty of packages.

I use NETStandard.Library version 1.6.1.

If you use System.Runtime.Serialization in your netstandard code, you have to install System.Runtime.Serialization.Primitives and System.Runtime.Serialization.Xml or .Json in the main project, too.

And also all other references of the netstandard project should be referenced in the main project, too.

Upvotes: 1

ste-fu
ste-fu

Reputation: 7444

It's worth pointing out that NuGet will install the most recent framework version at or below the target framework of your project. This means that when it was targeting 4.6.1 the referenced version would be net45 or 4.5 which drops you all the way down to Net Standard 1.1.

In theory upgrading to 4.7 should then mean that it references net462 but it could be that it is so bleeding edge that not everything is working properly. Did you try to update to 4.6.2?

Upvotes: 0

NightOwl888
NightOwl888

Reputation: 56859

The .NET Standard docs here and here have conflicting info when it comes to .NET Framework. I suspect the latter is the most current.

Basically, it indicates that .NET Framework is not supported on .NET Standard 1.6 unless you have the .NET Core 2.0 SDK installed.

Alternatively, .NET Standard 1.5 and below are supported with .NET Core 1.0 SDK installed.

Upvotes: 2

Related Questions