-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix Loading of Plugin Assemblies #6189
Changes from all commits
cc30d98
3e6e653
364eb66
0b3d41e
b86d06c
3de22d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,15 @@ internal sealed class CoreClrAssemblyLoader | |
|
||
private bool _resolvingHandlerHookedUp = false; | ||
|
||
private static readonly string _msbuildDirPath; | ||
private static readonly Version _currentAssemblyVersion = new Version(Microsoft.Build.Shared.MSBuildConstants.CurrentAssemblyVersion); | ||
|
||
static CoreClrAssemblyLoader() | ||
{ | ||
_msbuildDirPath = FileUtilities.NormalizePath(typeof(CoreClrAssemblyLoader).Assembly.Location); | ||
_msbuildDirPath = Path.GetDirectoryName(_msbuildDirPath); | ||
} | ||
|
||
public void AddDependencyLocation(string fullPath) | ||
{ | ||
if (fullPath == null) | ||
|
@@ -52,7 +59,12 @@ public Assembly LoadFromPath(string fullPath) | |
// folders in a NuGet package). | ||
fullPath = FileUtilities.NormalizePath(fullPath); | ||
|
||
if (Traits.Instance.EscapeHatches.UseSingleLoadContext) | ||
// If the requested load comes from the same directory as MSBuild, assume that | ||
// the load is part of the platform, and load it using the Default ALC. | ||
string assemblyDir = Path.GetDirectoryName(fullPath); | ||
|
||
if (Traits.Instance.EscapeHatches.UseSingleLoadContext || | ||
FileUtilities.ComparePathsNoThrow(assemblyDir, _msbuildDirPath, string.Empty)) | ||
{ | ||
return LoadUsingLegacyDefaultContext(fullPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: why is the default ALC called legacy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure. This is beyond my time in this code base. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The not-legacy ALC was a recent addition. rainersigwald tried to make it on by default, but that broke people, so he switched it to off-by-default but encouraged. It might have been turned on by default in the SDK; not sure. |
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ComparePathsNoThrow handles the normalization part of this for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Forgind. I'd like to leave this here. The reason is that it happens only once per process, and has the ability to simplify the checks that must happen per assembly, instead of just once per process. If we don't do this here, and the value would have changed, then when loading an assembly, we'd have to do a string comparison which would fail, and then we'd have to normalize both inputs, and then try again.
If on the other hand, the initial normalize call here changed the input, it could possibly avoid the extra normalizations per assembly load.