Repository navigation
Description
- .NET Core Version: happens both with
3.1.401and5.0.100-preview.8.20417.9 - Windows version: Win 10 (1909) 10.0.18363
- Does the bug reproduce also in WPF for .NET Framework 4.8?: for TFMs
netcoreapp3.1andnet50 - Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No, Visual Studio is not involved, only
dotnet buildfrom command line
This is essentially a duplicate of the closed #3183 ; the ticket was closed, although it was not resolved and I cannot re-open it. @ryalanms told me to reactivate when I see the issue again. Well, it has never been resolved for me. Sorry for the double-issue.
Problem description:
WPF core app doesn't build when adding a direct <Reference .../> to an old .Net 2.0 WinCE-compatible framework dll.
(Why would you do that? Expensive, proprietary dll from 3rd party, we can't live without it, author has retired)
Actual behavior:
dotnet build fails with either (SDK 3.1.401)
C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets(225,9):
error MC1000: Unknown build error, 'Could not find assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac'.
Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.'
or (SDK 5.0.100-preview.8.20417.9)
C:\Program Files\dotnet\sdk\5.0.100-preview.8.20417.9\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets(240,9):
error MC1000: Unknown build error, 'Could not find assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac'.
Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.'
Expected behavior:
dotnet build runs fine.
Minimal repro:
dotnet new wpf- TFM either
netcoreapp3.1ornet50 - Add a library reference to an old .Net Framework 2.0 WinCE library like so:
<Reference Include="SomethingOld" HintPath="SomethingOld.dll" /> dotnet build
Unfortunately I can't publish the proprietary dll here. It is built for .Net Framework 2 with WinCE compatibility.
@ryalanms said that is should be fixed in 3.1.401, but it is not fixed. He mentioned another version number 16.7.1 - unclear what for. Visual Studio is not involved and I've tested with different MSBuild versions too (the 5.0 preview comes with msbuild 16.8.0.xxx).
Activity
nzain commentedon Sep 9, 2020
Problem is not fixed in the new
3.1.402dotnet SDK:ryalanms commentedon Sep 9, 2020
Thank you for the report, @nzain. Sorry that the previous fix did not cover this scenario.
Did your project compile with a previous version of .NET Core?
nzain commentedon Sep 10, 2020
Good question - all my previous experiments with WPF core were rather simple. Thus, I don't know if it worked with an older version. However, I have a
netcoreapp3.1console application working on the exact same dlls for a long time. The<Project Sdk="Microsoft.NET.Sdk">works fine. Thus, it seems to be a WPF specific issue. Afterdotnet new wpfthe following fails to compile on3.1.402:When I create a
dotnet new consoleproject, the following works just fine:nzain commentedon Sep 15, 2020
The problem persists with the latest
5.0.100-rc.1.20452.10release canditate:ryalanms commentedon Oct 12, 2020
@nzain: Could you provide a project with a reference to a different public .Net 2.0 WinCE-compatible framework dll that reproduces the problem?
nzain commentedon Oct 14, 2020
@ryalanms please request a private copy vie e-mail (patrick_stalphATtrimble.com).
For the sake of completeness: the problem persists with the latest
5.0.100-rc.2.20479.15SDK.nzain commentedon Nov 11, 2020
@ryalanms I was able to create a Visual Studio 2008 csproj targeting .net v2.0 compact framework to reproduce the issue. The following zip file contains a VS2008 solution and the compiled dll (look for the
bin\debugfolder). If you want to compile yourself, you have to install Visual Studio 2008 and Microsoft .Net Compact Framework as well.VS2008-WinCE-lib.zip
As soon as you reference the above dll from a WPF Core project (tried today with
net5-windowson the new5.0.100SDK) you will get the error.Furthermore, a manual binding redirect for
mscorlibdoes not work. I added the followingApp.configwith no effect:Hope this helps to further diagnose the problem.
nzain commentedon Dec 2, 2020
@ryalanms can you reproduce the problem with the data linked above?
JensNordenbro commentedon Jan 8, 2021
I can confirm the same: One dll having a dependency to a thirdparty compact framework assembly that we "cannot easilly replace" gave the same results.
nzain commentedon Jan 20, 2021
This issue is blocking all potential migration work, there is no workaround up to now, and we are stuck on net 4.8 framework. I understand that developer resources are limited (very limited for WPF especially), but there has been no progress for several month! It would be nice to get some feedback on this at least (can you reproduce it, workaround ideas, milestone expectation).
JensNordenbro commentedon Jan 23, 2021
@nzain, In our case I managed to stub out our dependency, just mimicing the public api.
This ofcourse requires the code not to be the backbone of the application and of course later things needs to be re-implemented unless this is fixed and compatible with net5+. (winforms stuff might not due to reduced api coverage in >= netcore3.1 )
Maybe this approach will work for you, maybe not.... :)
Me, I have given up on the old thirdparty dependencies for CF, and probably we will either contact suppliers for buy-out of source code or just re-implement / replace the dependencies...
nzain commentedon Feb 23, 2021
The problem remains unresolved with
dotnet-sdk-6.0.100-preview.1.21103.13-win-x64and MS Build16.9.0-preview-21103-02+198f3f262.11 remaining items
nzain commentedon Aug 17, 2021
@ryalanms the fix you mentioned has been merged into the 3.1 release branch in January 2020. When do you expect to see this in a net 5/6 release?
"retargetable" - why do WPF apps require this, but console apps don't?
ryalanms commentedon Aug 17, 2021
@ericstj: Does a console application allow referencing assemblies built against a different version of mscorlib that do not use the 'retargetable' flag? Should WPF support this?
ericstj commentedon Aug 17, 2021
Different versions, yes. Retargetable is used to allow assemblies to change public key. By default the loader should permit newer versions of an assembly to satisfy older references. https://github.com/dotnet/runtime/blob/82f7144f791314885c0e4e86f16e579357bfe7e3/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/PathAssemblyResolver.cs#L75 cc @steveharter
I wouldn't expect the runtime to permit a different public key token without the retargetable bit, perhaps @vitek-karas or @agocke might know if it does (or if it allows this for mscorlib specially).
ryalanms commentedon Aug 25, 2021
@vitek-karas and @agocke: Is the runtime behavior different?
/cc @SamBent
vitek-karas commentedon Aug 26, 2021
As far as I can tell the runtime ignores retargetable flag. It will recognize it and store it and if asked can produce the full qualified name of the assembly with the
Retargetable=yessection in it. It can also parse such a name. But it doesn't use the value for anything.Also, runtime ignores public keys when binding assemblies. Meaning:
Also runtime doesn't verify the strong name in any way. It does persist the information (as seen above, the public keys are part of the assembly names), so it can be used in the app code to verify, but it will not do so itself.
ryalanms commentedon Aug 26, 2021
Thanks, @vitek-karas. @SamBent: We can discuss this in triage.
ericstj commentedon Aug 27, 2021
One other good piece of data to gather here: does the compiler permit it? If CSC is also ignoring publicKey it may be fair to ask SRM to relax the constraint. What happens in a normal net5 project where you build against this assembly and try to interact with its API that references types that would live in mscorlib?
djonesCenterEdge commentedon Jun 30, 2022
@singhashish-wpf has there been any more discussion regarding this?
singhashish-wpf commentedon Jul 1, 2022
@djonesCenterEdge No, there have not been any further updates on this, However the workarounds are already stated above. Let us know if you think those are not acceptable.
djonesCenterEdge commentedon Jul 1, 2022
@singhashish-wpf the workarounds stated above don't actually work, as the people who tried them also stated above. We managed to make it work by adding a dependency to
System.Runtime.CompilerServices.Unsafeand usingmsbuildinstead ofdotnetto build our our solutions.