diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/PresentationBuildTasks.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/PresentationBuildTasks.csproj index 61dbb1e744d00f81e73d213654e15012aced512f..37b21df095f0e4152cf2f397b546a6403772be8e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/PresentationBuildTasks.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/PresentationBuildTasks.csproj @@ -98,6 +98,9 @@ Shared\System\Windows\Markup\ReflectionHelper.cs + + Shared\System\Windows\Markup\RetargetablePathAssemblyResolver.cs + Shared\MS\Internal\Xaml\Parser\SpecialBracketCharacters.cs diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs index d2d536460bf22454c1ee43935aff4137c0b5ca79..b40c2c4c747c77f71e073d69a51ffa90af405919 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs @@ -62,7 +62,7 @@ internal static void Initialize(IEnumerable assemblyPaths) // System.Reflection.MetadataLoadContext Assembly cache _cachedMetadataLoadContextAssemblies = new Dictionary(StringComparer.OrdinalIgnoreCase); _cachedMetadataLoadContextAssembliesByNameNoExtension = new Dictionary(StringComparer.OrdinalIgnoreCase); - _metadataLoadContext = new MetadataLoadContext(new PathAssemblyResolver(assemblyPaths), MscorlibReflectionAssemblyName); + _metadataLoadContext = new MetadataLoadContext(new RetargetablePathAssemblyResolver(assemblyPaths), MscorlibReflectionAssemblyName); _localAssemblyName = string.Empty; } diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RetargetablePathAssemblyResolver.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RetargetablePathAssemblyResolver.cs new file mode 100644 index 0000000000000000000000000000000000000000..b35d218e63628380645d89cdb5303aaa0045d5df --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RetargetablePathAssemblyResolver.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.IO; +using System.Reflection; + +namespace MS.Internal.Markup +{ + public class RetargetablePathAssemblyResolver : MetadataAssemblyResolver + { + private PathAssemblyResolver _pathAssemblyResolver; + + public RetargetablePathAssemblyResolver(IEnumerable assemblyPaths) + { + _pathAssemblyResolver = new PathAssemblyResolver(assemblyPaths); + } + + public override Assembly Resolve(MetadataLoadContext context, AssemblyName assemblyName) + { + // PathAssemblyResolver will resolve the target assembly to the highest + // version of the target assembly available in the 'assemblyPaths' assembly + // list, only if the public key token for the target assembly is not set. + // Remove the public key token from 'mscorlib' to allow PathAssemblyResolver + // to resolve the most recent version of 'mscorlib'. + if (assemblyName.Name.Equals(ReflectionHelper.MscorlibReflectionAssemblyName)) + { + assemblyName.SetPublicKeyToken(null); + } + + return _pathAssemblyResolver.Resolve(context, assemblyName); + } + } +}