Remove PKT for mscorlib to allow PathAssemblyResolver to return most recent assembly version

This commit is contained in:
Ryland 41491307+ryalanms@users.noreply.github.com 2019-08-22 13:52:03 -07:00
Родитель 05ce539a03
Коммит c5cfbbfd3a
3 изменённых файлов: 39 добавлений и 1 удалений

Просмотреть файл

@ -98,6 +98,9 @@
<Compile Include="$(WpfSharedDir)\System\Windows\Markup\ReflectionHelper.cs">
<Link>Shared\System\Windows\Markup\ReflectionHelper.cs</Link>
</Compile>
<Compile Include="$(WpfSharedDir)\System\Windows\Markup\RetargetablePathAssemblyResolver.cs">
<Link>Shared\System\Windows\Markup\RetargetablePathAssemblyResolver.cs</Link>
</Compile>
<Compile Include="$(WpfSharedDir)\MS\Internal\Xaml\Parser\SpecialBracketCharacters.cs">
<Link>Shared\MS\Internal\Xaml\Parser\SpecialBracketCharacters.cs</Link>
</Compile>

Просмотреть файл

@ -62,7 +62,7 @@ namespace System.Xaml
// System.Reflection.MetadataLoadContext Assembly cache
_cachedMetadataLoadContextAssemblies = new Dictionary<string, Assembly>(StringComparer.OrdinalIgnoreCase);
_cachedMetadataLoadContextAssembliesByNameNoExtension = new Dictionary<string, Assembly>(StringComparer.OrdinalIgnoreCase);
_metadataLoadContext = new MetadataLoadContext(new PathAssemblyResolver(assemblyPaths), MscorlibReflectionAssemblyName);
_metadataLoadContext = new MetadataLoadContext(new RetargetablePathAssemblyResolver(assemblyPaths), MscorlibReflectionAssemblyName);
_localAssemblyName = string.Empty;
}

Просмотреть файл

@ -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<string> 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);
}
}
}