DispatchProxy does not allow for building collectible assemblies. #30032
Labels
area-System.Reflection
enhancement
Product code improvement that does NOT require public API changes/additions
Milestone
Currently when you create a DispatchProxy, it makes the DynamicAssembly that generates the IL an noncollectable assembly (it's hardcoded to use AssemblyBuildAccess.Run here). This makes it impossible to create DispatchProxies inside collectible AssemblyLoadContexts.
If you try and use this create within a collectible AssemblyLoadContext, it fails with
System.NotSupportedException: 'A non-collectible assembly may not reference a collectible assembly.'
A few options to fix this could be to change DispatchProxy's dynamic assembly to run with
AssemblyBuildAccess.RunAndCollect
, or allow for manually entering an option inDispatchProxy.Create<T, TProxy>()
to decide if it should be collectible or not.The text was updated successfully, but these errors were encountered: