Hello,
I have an issue using some .Net Core libraries, from France !
I had a .NET 4.5.1 library which I want to use in a new .NET Core project as a Nuget package. The package installed well on the .NET Core project, but when running, it stills wants to load the old assembly .Net Core (I suppose when trying to use Linq methods or collections methods) and I have the following error :
System.IO.FileLoadException Could not load file or assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The located assembly's manifest definition does not match the assembly reference
How can I fix it ? I do not found anywhere a solution to this issue.
Below is my .nuspec file :
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>***</id>
<version>***</version>
<title>***</title>
<authors>***</authors>
<requireLicenseAcceptance>***</requireLicenseAcceptance>
<description>***</description>
<summary>***</summary>
<copyright>***</copyright>
<tags>***</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="Serilog" version="2.4.0" />
<dependency id="StackExchange.Redis" version="1.2.1" />
<dependency id="Newtonsoft.Json" version="7.0.1" />
</group>
<group targetFramework=".NETStandard1.5">
<dependency id="Serilog" version="2.4.0" />
<dependency id="StackExchange.Redis" version="1.2.1" />
<dependency id="Newtonsoft.Json" version="10.0.2" />
</group>
</dependencies>
</metadata>
<files>
<file src="***.dll" target="lib\net45\***.dll" />
<file src="***.xml" target="lib\net45\***.xml" />
<file src="***.dll" target="lib\netstandard1.5\***.dll" />
<file src="***.xml" target="lib\netstandard1.5\***.xml" />
</files>
</package>
Thank you in advance.
Chifton
@ericstj thoughts?
I wouldn't expect that error for a .NETCore project. We have a System.Core.dll in the shared framework with the same identity (System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089). I've double-checked this in a recent build. /cc @weshaggard
@chifton please share some more details around how to reproduce your problem if you'd like us to take a closer look.
Hello,
Sorry for the late answer due to my jet lag in France.
Of course I am going to share my scenario with you. I just reproduced the same bug with a new example in 5 steps. Below is my explained scenario, with Visual Studio 2017 Version 15.1 :
1) I create a .NET 4.5 library project, where I use System.Linq and System.Collections.Generic which are part of System.Core, in a simple class with a simple method :
namespace LibraryCoreCheck
{
/// <summary>
/// The check two class.
/// </summary>
public class CheckerTwo
{
/// <summary>
/// The method to be used in .net core project after nuger package import.
/// </summary>
/// <param name="rootlist"></param>
/// <returns></returns>
public IList<int> ChooseTheFirstAndSecond(IList<int> rootlist)
{
var first = rootlist.FirstOrDefault(c => rootlist.IndexOf(c) == 0);
var second = rootlist.FirstOrDefault(c => rootlist.IndexOf(c) == 1);
return new List<int> { first, second };
}
}
}
2) I create a nuspec file and generates a package for that library with the command nuget pack LibraryCoreCheck.nuspec. Below is my nuspec file content (I specified on it that I want to target .NETStandard1.5 as your docs on .Net Core website explained on this link => [https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks] ):
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>LibraryCoreCheck</id>
<version>1.0.0</version>
<title>LibraryCoreCheck</title>
<authors>LibraryCoreCheck</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>LibraryCoreCheck</description>
<summary>LibraryCoreCheck</summary>
<copyright>LibraryCoreCheck</copyright>
<tags>LibraryCoreCheck</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="Serilog" version="2.4.0" />
<dependency id="StackExchange.Redis" version="1.2.1" />
<dependency id="Newtonsoft.Json" version="7.0.1" />
</group>
<group targetFramework=".NETStandard1.5">
<dependency id="Serilog" version="2.4.0" />
<dependency id="StackExchange.Redis" version="1.2.1" />
<dependency id="Newtonsoft.Json" version="10.0.2" />
</group>
</dependencies>
</metadata>
<files>
<file src="D:\AppTests\LibraryCoreCheck\LibraryCoreCheck\bin\Debug\LibraryCoreCheck.dll" target="lib\net45\LibraryCoreCheck.dll" />
<file src="D:\AppTests\LibraryCoreCheck\LibraryCoreCheck\bin\Debug\LibraryCoreCheck.xml" target="lib\net45\LibraryCoreCheck.xml" />
<file src="D:\AppTests\LibraryCoreCheck\LibraryCoreCheck\bin\Debug\LibraryCoreCheck.dll" target="lib\netstandard1.5\LibraryCoreCheck.dll" />
<file src="D:\AppTests\LibraryCoreCheck\LibraryCoreCheck\bin\Debug\LibraryCoreCheck.xml" target="lib\netstandard1.5\LibraryCoreCheck.xml" />
</files>
</package>
3) I create a new .Net Core project, where I import my previous .Net 4.5 library and I call the previous function as below :
class Program
{
static void Main(string[] args)
{
var checkerObject = new CheckerTwo();
var result = checkerObject.ChooseTheFirstAndSecond(new List<int> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
}
}
BUT it does not build and I got the following error :
The type Object is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, version 4.0.0.0
4) So to resolve, I imported and installed your following nuget package to make compatibility possible :
Microsoft.NETCore.Portable.Compatibility
5) The .Net Core project now builded, BUT I got the final error :
Could not load file or assembly 'System.Core, version=4.0.0.0' because of the manisfest...
Hope I well explained how I got this.
Don't hesitate if you need more informations.
Thank you.
Chifton
I see, so it sounds like this is NETCoreApp 1.0 or 1.1. In those versions we actually don't support loading desktop libraries in .NET Core. That support is something we started with NETCoreApp 2.0 for a subset of the desktop libraries that have type overlap with desktop.
In NETCoreApp 1.0 and 1.1 the Microsoft.NETCore.Portable.Compatibility package added support for mscorlib-based portable class libraries. These class libraries have the same reference assembly names as some desktop assemblies: mscorlib, system, system.core, etc, but their versions match the lowest version of all supported frameworks for the portable profiles: silverlight. As such the assembly versions of these are 2.0.5.0. They'll support loading PCL libraries, but not desktop libraries.
The root cause of the problem here is that you are packaging as netstandard1.5 but not building as netstandard1.5:
<file src="D:\AppTests\LibraryCoreCheck\LibraryCoreCheck\bin\Debug\LibraryCoreCheck.dll" target="lib\net45\LibraryCoreCheck.dll" />
<file src="D:\AppTests\LibraryCoreCheck\LibraryCoreCheck\bin\Debug\LibraryCoreCheck.dll" target="lib\netstandard1.5\LibraryCoreCheck.dll" />
That's why your assembly has references to versions that are higher. If you want to package as netstandard1.5 you should also build against that, see https://docs.microsoft.com/en-us/nuget/guides/create-net-standard-packages-vs2017.
Hello,
Yes it is .Net Core 1.1. Thank you for your clear answer, I understand. I will build it regarding your link.
When will .Net Core 2.0 be available ?
Chifton
Q3 this year. See https://github.com/dotnet/core/blob/master/roadmap.md.
Okay thank you !
Connect-AzureRmAccount: Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. please help
Most helpful comment
Hello,
Sorry for the late answer due to my jet lag in France.
Of course I am going to share my scenario with you. I just reproduced the same bug with a new example in 5 steps. Below is my explained scenario, with Visual Studio 2017 Version 15.1 :
1) I create a .NET 4.5 library project, where I use System.Linq and System.Collections.Generic which are part of System.Core, in a simple class with a simple method :
2) I create a nuspec file and generates a package for that library with the command nuget pack LibraryCoreCheck.nuspec. Below is my nuspec file content (I specified on it that I want to target .NETStandard1.5 as your docs on .Net Core website explained on this link => [https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks] ):
3) I create a new .Net Core project, where I import my previous .Net 4.5 library and I call the previous function as below :
BUT it does not build and I got the following error :
4) So to resolve, I imported and installed your following nuget package to make compatibility possible :
5) The .Net Core project now builded, BUT I got the final error :
Hope I well explained how I got this.
Don't hesitate if you need more informations.
Thank you.
Chifton