-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use assembly loading context to isolate loaded assemblies from AppDomain #714 #716
Use assembly loading context to isolate loaded assemblies from AppDomain #714 #716
Conversation
@andrerav what are the chances this can get merged any time soon and released as pre release? Our org relies on this package and this is a blocker for us. We can run off of our fork if it's going to be awhile. Thanks! |
Fix/isolated assemblies
9f42a48
to
86fd5c4
Compare
@andrerav done and done thanks! |
@andrerav as far as I can tell there are no changes to consumer-facing APIs of the library. It has been a long time since I made this change though, are you seeing something specific? Also: you're very welcome! |
Ah, disregard that. I had a brief lapse of reason :) |
Mapster.Tool update to solve issue #714
TL; DR
Replace Assembly.LoadFrom calls with something more robust that prevents assembly/type collisions between the assemblies in the running Mapster.Tool process (such as .NET framework assemblies) and the scanned assemblies - while also preserving the ability to scan for attributes that are in the Mapster assembly (using share Assembly resolution).
See Pertinent MSFT Docs
More detail
Added an AssemblyLoadContext implementation for dynamically loading assemblies when scanning in an isolated way so that they don't have collisions with all of the assemblies loaded by Mapster by default (for example framework assemblies such as System.Text.Json).
The implementation also allows the setting of a subset of assembly names that will be shared with AssemblyLoadContext.Default (the default context that all assemblies are resolved from if no custom ALC were created). Some scanned types need to be owned by the default assembly context such as those from the "Mapster" assembly.
The end result is that we can resolve types from the target assembly being scanned, and we can do things like .GetCustomAttribute() and the attribute will be found because it comes from a shared assembly across the default (runtime) AssemblyLoadContext and the custom one used to avoid collisions.