Open AraHaan opened 3 years ago
Tagging subscribers to this area: @vitek-karas, @agocke, @vsadov See info in area-owners.md if you want to be subscribed.
Author: | AraHaan |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-AssemblyLoader-coreclr`, `untriaged` |
Milestone: | - |
Like for example you try to load an assembly in AssemblyLoadContext that uses a type in System.Windows.Forms.dll that does not exist anymore on .NET 5
Why is it not an option to recompile these assemblies for .NET 5? It would be highly preferable to trying to patch things up at runtime.
.NET 5.0.x and 6.0
Not going to happen - too late to consider.
Like for example you try to load an assembly in AssemblyLoadContext that uses a type in System.Windows.Forms.dll that does not exist anymore on .NET 5
Why is it not an option to recompile these assemblies for .NET 5? It would be highly preferable to trying to patch things up at runtime.
.NET 5.0.x and 6.0
Not going to happen - too late to consider.
Because not always are these assemblies able to be recompiled (in terms of plugins for Paint.NET some of them are covered under their own copyrights), some are unmaintained, and some are outright not open source + has a copyright preventing one from decompiling and recompiling it for .NET 5+ (well in a way that is legal / does not violate it's EULA that is) + unmaintained.
Could this be possibly looked into for .NET 7?
I doubt that we will ever add this feature.
It has very complex interactions with many parts of the system, the motivating scenario is very niche, and the feature does not address it completely - there can be also missing methods, missing interfaces, and behavior changes to patch. Patching the IL is the only way reasonable way to shim for all these incompatibilities.
True, but patching the IL is sometimes impossible if R2R is involved without needing to strip R2R first.
As for missing members, one can catch the MemberNotFoundException
and then read the message for the missing "type", then load an assembly that stubs those missing members (assuming they are not static ones) from another assembly that adds them back using extension methods, and then retry the call. However doing that properly is almost impossible to do as well on that one so I agree with that part.
@AraHaan, collectible AssemblyLoadContext
s ignore R2R data, https://github.com/dotnet/runtime/blob/main/docs/design/features/unloadability.md (see "Unsupported Scenarios")
I want to add something onto this. We (the IKVM project) make great use of AppDomain.TypeResolve to generate types in dynamic assemblies on the fly as required by the runtime. While we don't do things like patch and rename types: we generate them exactly as requested, it is worrying that the API hasn't been moved from AppDomain. It speaks to the existing functionality maybe not being something that folks are committed to for the long term.
The ability to do this is pretty core to IKVM.
I would like to see TypeResolve moved off AppDomain some day. It would make me a bit more confident it was something that was going to stick around.
The events (including TypeResolve event) on AppDomain type are not going anywhere. We have stopped introducing their duplicates with better names when the AppDomain type was re-introduced with .NET Standard 2.0.
For example, see the discussion about UnhandledException at https://github.com/dotnet/runtime/issues/16468#issuecomment-251832080 .
If you would like to see the earlier decision re-evaluated and propose duplicates for events on AppDomain type somewhere else, it would be best to start a new discussion issue about it.
Background and motivation
As mentioned here https://github.com/dotnet/winforms/issues/5368 AssemblyLoadContext lacks an event where you can subscribe too when a type resolution fails (Like for example you try to load an assembly in AssemblyLoadContext that uses a type in
System.Windows.Forms.dll
that does not exist anymore on .NET 5 and you then need to reroute it to load a "fake" version of those removed types located in another assembly which actually wraps the types that they were replaced with so those old and possibly unmaintained assemblies would work like usual).@rickbrew could benefit from this in Paint.NET if this was possible in AssemblyLoadContext currently.
API Proposal
API Usage
Risks
This would probably need to be considered for addition in .NET 5.0.x and 6.0 so Paint.NET can use it.