Skip to content

Add System.Reflection.PathAssemblyResolver support for 'retargetable' assemblies #30663

Closed

Description

@ryalanms

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

If any assemblies loaded by MetadataLoadContext were built against some older versions of mscorlib, PathAssemblyResolver will fail to match any newer versions of mscorlib present in assemblyPaths, due to a public key token mismatch. PathAssemblyResolver already supports taking the most recent version for target assemblies with an empty public key token.

https://github.com/dotnet/corefx/blob/master/src/System.Reflection.MetadataLoadContext/src/System/Reflection/PathAssemblyResolver.cs#L80

Add support for most-recent assembly match when assembly being resolved is 'retargetable'.

Activity

  1. vatsan-madhavan commented on Aug 22, 2019

    @vatsan-madhavan
    Member
  2. vatsan-madhavan commented on Aug 22, 2019

    @vatsan-madhavan
    Member

    We are trying to address dotnet/wpf#1451 (potentially for 3.0). @ryalanms thinks that we'd need our own implementation of a MetadataAssemblyResolver that's almost exactly like PathAssemblyResolver, with a bit of extra intelligence for dealing with retargetable assemblies.

    This seems more suitable for PathAssemblyResolver itself. Thoughts?

    /cc @rladuca

  3. ericstj commented on Aug 22, 2019

    @ericstj
    Member

    Can you wrap PathAssemblyResolver?

  4. ryalanms commented on Aug 22, 2019

    @ryalanms
    MemberAuthor

    Yes, we could but PathAssemblyResolver has private members, and the wrapper would need to keep track of the assemblyPaths and have similar matching logic and error handling.

  5. ericstj commented on Aug 22, 2019

    @ericstj
    Member

    Maybe a better way to phrase this is that PathAssemblyResolver ought to use a resolution policy that is similarly permissive as the normal load path. Presumably that normal load path handles retargetable assemblies correctly. @vitek-karas

  6. ryalanms commented on Aug 22, 2019

    @ryalanms
    MemberAuthor

    It also looks like RoAssemblyName doesn't support AssemblyName.Flags, which includes AssemblyNameFlags.Retargetable.

  7. steveharter commented on Aug 23, 2019

    @steveharter
    Contributor

    I have a prototype at https://github.com/steveharter/dotnet_corefx/tree/RetargetableAsm

    It adds support for AssemblyNameFlags.Retargetable and does the extra check in PathAssemblyResolver to detect.

    Due to the AssemblyNameFlags.Retargetable support, it can't be worked around in a custom\wrapped PathAssemblyResolver.

    Thus we need to determine if this meets the bar for 3.0 -- how common is this scenario?

  8. ryalanms commented on Aug 23, 2019

    @ryalanms
    MemberAuthor

    Thanks, @steveharter. This looks great.

    Any applications ported from .NET Framework to .NET Core that rely on older versions of NuGet packages may hit this, so I believe it is a common scenario.

  9. vatsan-madhavan commented on Aug 23, 2019

    @vatsan-madhavan
    Member

    @ericstj thoughts on how common this is going to be, and whether this will become a common enough issue during migration?

  10. steveharter commented on Aug 26, 2019

    @steveharter
    Contributor

    Short-term, I'll get the PR out for master today.

  11. ericstj commented on Aug 26, 2019

    @ericstj
    Member

    that rely on older versions of NuGet packages may hit this, so I believe it is a common scenario.

    Can you clarify what is special about these? Desktop assemblies don't rely on retargetable, so this must only be for v1 PCLs that used the Silverlight key? I suspect there are still some of these out there, but I don't have a read on how many: I know all the ones we produced are superseded with newer contract-based versions which don't rely on retargetable. Seems like something we could measure with the right data. I know we've scanned packages for similar sorts of things in the past. /cc @terrajobst

  12. steveharter commented on Aug 26, 2019

    @steveharter
    Contributor

    Desktop assemblies don't rely on retargetable, so this must only be for v1 PCLs that used the Silverlight key?

    That is my understanding. I can create such an assembly (Retargetable mscorlib reference with version=2.0.5.0 PublicKey=7cec85d7bea7798e) with VS 2017 and a Universal Windows class library. At compile-time, a reference assembly like this is used: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile344\mscorlib.dll.

    I don't think this would be a common scenario, so I'm also interested to know how older NuGet packages could influence this.

  13. steveharter commented on Aug 26, 2019

    @steveharter
    Contributor

    Note a potential temporary work-around would be to create a custom resolver that checks for the presence of that reference and treat it as "relocatable":

    • Name: mscorlib
    • Version: 2.0.5.0
    • PublicKeyToken: 7cec85d7bea7798e
  14. 3 remaining items

  15. ericstj commented on Aug 27, 2019

    @ericstj
    Member

    Good point on desktop, I had forgotten that this component works on desktop as well. I'm ok with the change to honor retargetable.

    As far as workaround vs fix, I'd actually feel better about fixing the right way, given WPF is one of the primary consumers of MetadataLoadContext. Either way we need to put in a code change, so I'd prefer that change not be a hack. My inclination would be to fix in MetadataLoadContext or no fix at all. Let me double check with tactics.

  16. vatsan-madhavan commented on Aug 27, 2019

    @vatsan-madhavan
    Member

    My inclination would be to fix in MetadataLoadContext or no fix at all

    👍

  17. ericstj commented on Aug 27, 2019

    @ericstj
    Member

    I brought this up in tactics and their indication was won't fix for now and consider for 3.1 if we get more feedback on this blocking multiple packages.

  18. steveharter commented on Aug 27, 2019

    @steveharter
    Contributor

    Note that master currently has the fix explained earlier for retargetable assemblies.

  19. hallatore commented on Aug 28, 2019

    @hallatore

    I brought this up in tactics and their indication was won't fix for now and consider for 3.1 if we get more feedback on this blocking multiple packages.

    It seems to block a lot of legacy WPF apps when porting them to core. And as it stands now there are no workaround to fix it, since the nuget packages causing this usually are quite old.

    This also worked in preview3 and earlier. So my Netling app is already ported and working. As long as I compile it with the old preview SDK.

  20. ericstj commented on Aug 28, 2019

    @ericstj
    Member

    I took a look at Netling and it looks like it's failing due to a dependency on "OxyPlot.Wpf". I took a look at this package on NuGet.org and the version you depend on is actually unlisted. A newer version (by date) 1.0.0 is available. If I change your project to use this newer version it works:
    https://github.com/hallatore/Netling/blob/68ae5940e31a052d801bc15ecfb598ccd5f1e4d7/Netling.Client/Netling.Client.csproj#L11-L12

    -    <PackageReference Include="OxyPlot" Version="2014.1.546.0" />
    -    <PackageReference Include="OxyPlot.Wpf" Version="2014.1.546.0" />
    +    <PackageReference Include="OxyPlot.Wpf" Version="1.0.0" />

    To workaround it you can avoid passing the reference to the XAML compiler, though this might not always be possible. If more folks hit it let us know about the old package you are using. If it turns out to be a bigger issue than folks are assuming we can re-evaluate pulling the fix into 3.0.

  21. terrajobst commented on Aug 28, 2019

    @terrajobst
    Contributor

    Given the (lack of) adoption of PCLs on NuGet, it seems @ericstj's suggestion should work for most components that are likely used by WPF apps. Postponing this until we see more evidence for this seems reasonable. Bringing all the complexity of PCLs v1 doesn't seem worth it at this point.

  22. ericstj commented on Aug 28, 2019

    @ericstj
    Member

    Closing as this is fixed in master and currently "won't fix" for 3.0.

  23. transferred this issue fromdotnet/corefxon Feb 1, 2020
  24. added this to the 3.0 milestone on Feb 1, 2020
  25. matanyos commented on Feb 4, 2020

    @matanyos

    the issue is still there in .netcore 3.1 ... as @ericstj said it occures on
    mscorlib
    System
    System.Core
    System.Net
    System.Runtime.Serialization
    System.ServiceModel.Web
    System.Windows
    System.Xml

    please advise

  26. ericstj commented on Feb 4, 2020

    @ericstj
    Member

    The fix was taken in servicing for 3.1; see dotnet/corefx#42768. To get it you'll need the latest servicing build of 3.1.2. @mmitche / @Anipik is this available yet?

  27. Anipik commented on Feb 4, 2020

    @Anipik
    Contributor

    no, 3.1.2 is not available yet

  28. ghost locked as resolved and limited conversation to collaborators on Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions