8

I've created a Portable Class Library with the following projects.json

{
  "supports": {},
  "dependencies": {
    "Microsoft.CSharp": "4.0.1",
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "NETStandard.Library": "1.6.0",
    "System.Runtime.Serialization.Primitives": "4.1.1",
    "System.Runtime": "4.1.0"
  },
  "frameworks": {
    "net451": {},
    "netstandard1.5": {}
  }
}

However, when referencing this from an ASP.NET application (not ASP.NET Core), I get the following runtime exception:

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.

If I reference it from a console application it runs without issues.

Any ideas?

Edit

Found a solution here: https://stackoverflow.com/a/37639003/691045

Community
  • 1
  • 1
Tom
  • 1,561
  • 4
  • 20
  • 29
  • Does your ASP.NET application use `project.json`? Are you loading your shared library via NuGet or directly referencing it? – Nate Barbettini Jul 11 '16 at 16:28
  • No, it's just targeting .NET 4.6, and I'm directly referencing it. As I said, I have got that setup working in a test solution, although I think I only got that working after removing the reference and re-adding it - before that I got the same error. So I'm not too sure what the issue is. – Tom Jul 11 '16 at 18:18
  • 2
    Directly referencing a .NET Core project from a .NET project doesn't work very well right now. If you produce a nuget package (dotnet pack) from your .NET Core library, then install the package in the .NET project, you might have better/more consistent luck. – Nate Barbettini Jul 11 '16 at 18:19
  • Thanks @NateBarbettini, it looks like that's the only option right now. – Tom Jul 12 '16 at 12:53

3 Answers3

5

As mentioned in the update one solution to this problem is to package up the PCL as a nuget package. This however goes contrary to what one is trying to do when one targets .Net Standard with a PCL. Also the package solution becomes cumbersome to debug.

To me it appears as a bug with Net Core Tools Preview when crossing the csproj to xproj boundary. To evidence this if one install the package via nuget:

Install-Package System.Runtime

The System.Runtime looks correct in the project.json as "System.Runtime": "4.1.0". Looking at the references, one will see that the version is listed as System.Runtime (4.0.20). Also the actual bin has absolutely reference to the actual dll.

Simply copying the .Net 4.6.2 dll from the nuget cache into the bin solves the problem. This allows for direct references without packaging up your PCL.

Hopefully when we hit Net Standard 2.0 and the tooling matures a bit more this type of thing will be a thing of the past.

UPDATE: If you use the latest .Net Core release (1.1) and binaries this is fixed. The tool preview is still on 1.0.1 so you have to make sure you install the binaries for 1.1.

Sarel Esterhuizen
  • 1,628
  • 17
  • 18
0

I was getting a similar warning from ReSharper while running unit tests:

The solution that worked for me was to run this in the Package Manager console:

Update-Package System.Runtime -Reinstall

What I observed is that before running the above command, the reference in the affected project was to System.Runtime v 4.0.20.0, but post execution, it changed to 4.1.1.0

Sudhanshu Mishra
  • 6,523
  • 2
  • 59
  • 76
0

I was experiencing this issue after upgrade the .NET framework from 4.6.2 to 4.7, after digging around on several forums and the internet for a while and trying a lot, I found a solution and consits in two steps:

  1. I deleted all Dependent Assambly and update all nugets UPDATE-PACKAGE -projectName -reinstall.

  2. After the first step, I checked every missing assambly that throw me an exception in runtime and realize that in some cases the framework has a dll in our local machine that has nothing to do with the nuget then I deleted all local's dll references and install it from the nuget. After cleaning from the missing dll taking them from the Nuget my project run without any issue.

Hope that help you.