Wpf: Microsoft.WinFX.targets Unknown build error Could not find assembly 'mscorlib'

Created on 25 Jun 2020  路  9Comments  路  Source: dotnet/wpf

  • .NET Core Version: Version: 3.1.301, Commit: 7feb845744
    Base Path: C:\Program Files\dotnetsdk\3.1.301\
    Host (useful for support): Version: 3.1.5, Commit: 65cd789777
  • Windows version: Win 10 (1909) 10.0.18363
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Not when creating a classic WPF full Framework project
  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? no, dotnet build fails (without VS being involved)

    Problem description:
    WPF core app doesn't build when adding a direct <Reference .../> to an old .Net 2.0 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

C:\Program Files\dotnet\sdk\3.1.301\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.' [D:\Downloads\DotnetWpfCoreProblem\DotnetWpfCoreProblem.csproj]

Expected behavior:
It builds fine.

Minimal repro:
Create a new WPF core project: dotnet new wpf which will target netcoreapp3.1 at the time of writing.
Add a library reference to an old .Net Framework 2.0 WinCE library. Something like

<Reference Include="SomethingOld" HintPath="SomethingOld.dll" />

Try to build. Unfortunately I can't publish the proprietary dll here. It is built for .Net Framework 2 with WinCE compatibility.

Related Issues
I found similar topics where the build failed with the same error (mscorlib not found), but they seem to be resolved.
https://github.com/dotnet/wpf/issues/1451
https://github.com/dotnet/wpf/issues/2274

issue-type-bug

Most helpful comment

@wldevries If you just updated Visual Studio you are more likely hitting this: https://github.com/dotnet/sdk/issues/12710

All 9 comments

@nzain - could you provide an isolated repro? (just the metadata from the assembly/ildasm)

Not sure what exactly that should be. Tomorrow, I'll add the project+output (if anything was generated) except for that proprietary lib.

dotnet wpf issue 3183.zip

@fabiant3 Attached is everything that was generated so far. bin is empty (as expected) but hopefully you find what you're looking for in obj. If not, please explain how to get the required data.

I'm not sure how this relates to what I'm experiencing, but my WPF builds produce the exact same build error in the following scenario:

  • Empty Microsoft.NET.Sdk.WindowsDesktop project targeting net47. Reproduce by creating a NET Core WPF project and change the target to net47
  • PackageReference to CommonServiceLocator 1.3.0

This is a tiny repro from one of our products that depends on an older version of Prism that uses CommonServiceLocator. We updated all of our NET Framework projects to the new Microsoft.NET.Sdk project system, which might not have been smart in hindsight.

@wldevries If you just updated Visual Studio you are more likely hitting this: https://github.com/dotnet/sdk/issues/12710

This should be fixed in 16.7.1 and 3.1.401. Please reactivate if you see it again. Thanks!

@ryalanms I guess you talk about msbuild 16.7.1? I have dotnet SDK 3.1.401 installed (and the current 5.0 preview), but my msbuild is 16.7.0-preview-20360-03+188921e2f. The github msbuild releases https://github.com/dotnet/msbuild/releases are outdated. Where can I get version 16.7.1?

Just to clarify, the issue is not resolved for me right now.

This issue is not fixed for me.

The latest dotnet SDK 5.0.100-preview.8.20417.9 comes with Microsoft (R) Build Engine version 16.8.0-preview-20414-02+a55ce4fbb, but the issue is unchanged: mscorlib, Version=2.0.0.0 is not found.

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.'

Switching the TargetFramework to net5.0 doesn't make a difference.
@ryalanms commented Please reactivate, if you see it again. but I cannot change the ticket status.

Was this page helpful?
0 / 5 - 0 ratings