Manifest mismatch exception when referencing Microsoft.NETCore.App 1.2.0 for an application targeting netcoreapp1.0
dotnet --version: 1.0.0-preview2-1-003180 (This CLI which supports netcoreapp1.1 > netstandard1.7
project.json:
{
"buildOptions": {
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.2.0-*"
},
"System.ComponentModel.TypeConverter": "4.4.0-*"
}
}
}
}
Program.cs
public class Program
{
public static void Main() => System.Console.WriteLine("Hello World!");
}
Running dotnet run on the project fails with
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Threading, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at System.Console.EnsureInitialized[T](T& field, Func`1 initializer)
at System.Console.get_Out()
at System.Console.WriteLine(String value)
at Program.Main() in \mna-2\Program.cs:line 3
cc @ericstj
Curious what shared framework this is even running on. If you constructed the CLI then I imagine you constructed the shared framework as well.
Can you share more about what assembly has the Thread 4.1 ref, where that assembly lives (shared/app), and where Thread is coming from (shared/app)?
We install the shared runtime separately in addition to installing the CLI. The version of Microsoft.NETCore.App we restore \ shared runtime we install is 1.2.0-beta-001202-00. Here's the lock file for the project: https://gist.githubusercontent.com/pranavkm/7641e9f37e5c4113eba4ee21a816e143/raw/91bcf74d46ea054205dc3f3756eeb9fcfba1c58b/project.lock.json - would that answer your second question?
Not exactly. Trying to understand what brought in a reference to Thread 4.1. Nothing published with the app should have that: if it does it's a bug in that library. Stuff in the shared framework would have that (since it is actually NCA-v-next), but the shared framework will have Thread 4.1 since it's the latest shared framework. If it doesn't that could be a bug in the shared framework build if it's not being built with the new mappings.
The only trace of that version I could find was in the shared runtime. If I make the application standalone, the issue goes away. Could this be an issue with the authoring of the shared runtime? Here's where we're installing it from: https://dotnetcli.blob.core.windows.net/dotnet/preview/Binaries/1.0.0-preview2-003121/dotnet-dev-win-x64.1.0.0-preview2-003121.zip.
that only has the 1.0.0 shared runtime. where are you getting the 1.2.0-beta-001202-00 shared runtime from?
@ericstj - sorry wrong link. Here's where we're getting the shared runtime from: https://dotnetcli.azureedge.net/dotnet/master/Binaries/1.2.0-beta-001202-00/dotnet-win-x64.1.2.0-beta-001202-00.zip
Actually, thinking about this more, I think this is a fundamental problem with how CLI/NuGet treats the shared framework (and also what we support in the package).
I believe what's happening here is that you're referencing a newer System.Threading.Thread package version than is in MS.NETCore.App. This is because @weshaggard added the 1.0 packages to MS.NC.A, but even if he hadn't we'd hit this case, for example using the 1.1 MS.NC.A, targeting nca1.0, but then referencing some package newer than 1.1.
So you have a newer package, but you're resolving it for NetCoreApp1.0, when the shared framework you're running on is netcoreapp1.1, or even later. The host will prefer the local assembly rather than shared framework assembly. This assembly is actually older than what's in the shared framework (what you're running on: netcoreapp1.1) since it supports netcoreapp1.0 (what was targeted). You've effectively downgraded the assembly even for refs inside the shared framework. Causing this ref-def mismatch.
Perhaps we shouldn't be supporting old TFMs on newer shared frameworks. /cc @davidfowl
Agree with that assessment. @nguerrera came to a similar conclusion on an issue we had with the SDK inferring the package from the TFM.
Should we move the bug to CLI then? Or is there something in CoreFX could/should do?
We should have a plan for what to do. I see the following options.
- Do nothing and leave it broken.
- Don't pretend to support old TFMs in the new package. Make it only install on the TFM that was used for building the shared framework.
- Make the host smarter about choosing the best assembly (app vs shared framework) at runtime.
Any other ideas @davidfowl @schellap?
I suppose another option is 4. Make build / publish smarter about deciding when to copy things app local.
Don't pretend to support old TFMs in the new package. Make it only install on the TFM that was used for building the shared framework.
I kinda like this. It makes things easier to reason about. Also this package is becoming more of an implementation detail.
Make the host smarter about choosing the best assembly (app vs shared framework) at runtime.
AKA don't allow downgrades? This was originally discussed but then we just decided to let the application win.
/cc @schellap
I discussed some more with @dsplaisted and we came up with another option. 5. Don't assume that package version = shared framework version. Instead have the SDK read a data file (or consume an MSBuild property) that defines what the shared framework version is. That way you can use the latest Core.App package, but you'll target whatever version of the shared framework is appropriate for your TFM.
I'm not a fan of that. More version numbers just sounds like more chaos to me. When the versions align, it's easier to line things up and manage.
Another option is we would simply use the TFM property specified in the project file to do the framework lookup instead of using the package name Microsoft.NETCore.App. Once we select the TFM based folder name, we'd use the MNA version inside that folder. We can still continue the app to win.
- dotnet.exe
- shared
- netcoreapp20
@schellap That might be nice, but how would patch versions of the runtime be handled? Today the TFM is still netcoreapp1.0 even if the runtime you're targeting is 1.0.3.
Also, would there ever be different shared frameworks for the same target framework, for example a .NET Native and JIT version of netcoreapp?
but how would patch versions of the runtime be handled?
we'd use the MNA version inside that folder
Today we look up with package name and package version. We can lookup using tfm name and package version or error out. See https://github.com/dotnet/core-proposals/blob/master/DotNetCore-SharedPackageStore.md#dotnet-build
Closing old issue