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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With