wpf: Preview 7: 'Could not find assembly 'mscorlib...' in Microsoft.WinFX.targets

Hi! On .Net Core 3.0 Preview 7, VS 16.3 Preview 1.

My only error for my WPF project is below (a similar WinForms project that depends on the same assemblies is building and running fine). I have no explicit dependencies on mscorlib, but possibly an implicit one via a 3rd party dependency. Is this a forwarding issue specific to WPF? If so, how to resolve? Thanks!!

Error MC1000 Unknown build error, ‘Could not find assembly ‘mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e’. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.’ C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets 243

C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets(243,9): error MC1000: Unknown build error, ‘Could not find assembly ‘mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e’. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.’

Done executing task “MarkupCompilePass1” – FAILED.

<MarkupCompilePass1
              Language="$(Language)"
              UICulture="$(UICulture)"
              ApplicationMarkup="@(ApplicationDefinition)"
              SplashScreen="@(SplashScreen)"
              LanguageSourceExtension="$(DefaultLanguageSourceExtension)"
              PageMarkup="@(Page)"
              ContentFiles="@(Content)"
              AssemblyName="$(AssemblyName)"
              OutputType="$(OutputType)"
              AssemblyVersion="$(AssemblyVersion)"
              AssemblyPublicKeyToken="$(AssemblyPublicKeyToken)"
              References="@(ReferencePath)"
              RootNamespace="$(RootNamespace)"
              KnownReferencePaths="$(MSBuildBinPath);$(TargetFrameworkDirectory);@(_TargetFrameworkSDKDirectoryItem);@(KnownReferencePaths)"
              AssembliesGeneratedDuringBuild="@(AssembliesGeneratedDuringBuild)"
              AlwaysCompileMarkupFilesInSeparateDomain="$(AlwaysCompileMarkupFilesInSeparateDomain)"
              HostInBrowser="$(HostInBrowser)"
              LocalizationDirectivesToLocFile="$(LocalizationDirectivesToLocFile)"
              ContinueOnError="$(_IntellisenseOnlyCompile)"
              SourceCodeFiles="@(Compile)"
              DefineConstants="$(DefineConstants)"
              ExtraBuildControlFiles="@(ExtraBuildControlFiles)"
              XamlDebuggingInformation="$(XamlDebuggingInformation)"
              IsRunningInVisualStudio="$(BuildingInsideVisualStudio)"
              OutputPath="$(IntermediateOutputPath)">


             <Output ItemName="GeneratedBaml" TaskParameter="GeneratedBamlFiles"/>
             <Output ItemName="GeneratedLocalizationFiles" TaskParameter="GeneratedLocalizationFiles" />
             <Output PropertyName="_RequireMCPass2ForMainAssembly" TaskParameter="RequirePass2ForMainAssembly" />
             <Output PropertyName="_RequireMCPass2ForSatelliteAssemblyOnly" TaskParameter="RequirePass2ForSatelliteAssembly" />
             <Output ItemName="Compile" TaskParameter="GeneratedCodeFiles" />

             <!-- Keep a list of all the generated files, it is used to clean up for a next clean build -->
             <Output ItemName="FileWrites" TaskParameter="AllGeneratedFiles" />

             <Output ItemName="_GeneratedCodeFiles"
                     TaskParameter="GeneratedCodeFiles" />


       </MarkupCompilePass1>

_Originally posted by @dcuccia in https://github.com/dotnet/core/issues/3075#issuecomment-515806022_

/cc @ryalanms, @grubioe /cc @dotnet/wpf-developers

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 19 (11 by maintainers)

Most upvoted comments

Thanks for the repro @dcuccia. The problem is that PresentationBuildTasks is not accommodating ‘retargetable’ assembly references.

// Metadata version: v4.0.30319 .assembly extern retargetable mscorlib { .publickeytoken = (7C EC 85 D7 BE A7 79 8E ) // |…y. .ver 2:0:5:0 }

Version 4.0.1 of pulls in CommoneServiceLocator, which contains Microsoft.Practices.ServiceLocation.dll. Microsoft.Practices.ServiceLocation.dll was built against mscorlib version 2.0.5.0.

At compile time PresentationBuildTasks loads assemblies in a ‘reflection-only’ context (for the type table, etc). When any types in reflection-only assemblies have dependencies on other assemblies, MetadataLoadContext's assembly resolver is invoked to find the required dependent assembly. To match an assembly in the reference list, the assembly name, version, and public key token must match. If the names and public key tokens match, the highest version of the assembly will be loaded in to the reflection-only context. If the public key token of the requested assembly does not match any assembly in the reference list, the markup compilation task will fail.

A new MetadataAssemblyResolver needs to be added that supports retargetable references, or at least supports a retargetable mscorlib reference. If a different, newer version of mscorlib is available at compile time, we should ignore the public key token mismatch, when the mscorlib reference is marked ‘retargetable’.

I agree with @rladuca that we should just fix this in CoreFX.

@ryalanms it seems like you should just be able to wrap PathAssemblyResolver with code that first checks for a retargetable assembly and handles those cases while passing any other scenarios directly to an instance of PathAssemblyResolver.

I also see a similar behaviour in preview7 and preview8 with targetframework net461.

This will reproduce it

dotnet new wpf
change TargetFramework to net461
dotnet add package Common.Logging --version 3.4.1
dotnet build

You can also clone https://github.com/hsorbo/wpfbug