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
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:
The
System.Runtime
looks correct in theproject.json
as"System.Runtime": "4.1.0"
. Looking at the references, one will see that the version is listed asSystem.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.
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:
I deleted all Dependent Assambly and update all nugets UPDATE-PACKAGE -projectName -reinstall.
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.
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:
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