Use assembly loading context to isolate loaded assemblies from AppDomain #714#716
Merged
andrerav merged 9 commits intoMapsterMapper:developmentfrom Jan 2, 2025
Merged
Conversation
Contributor
Author
|
@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
requested changes
Dec 22, 2024
Contributor
Author
|
@andrerav done and done thanks! |
andrerav
approved these changes
Jan 2, 2025
Member
Contributor
Author
|
@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! |
Member
|
Ah, disregard that. I had a brief lapse of reason :) |
This was referenced Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.