Skip to content

Commit 59adb4b

Browse files
committed
Workaround Core CLR p/invoke load context bug
Fixes #215
1 parent dfd2c88 commit 59adb4b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/MSBuildExtensionTask/ContextAwareTask.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ internal CustomAssemblyLoader(ContextAwareTask loaderTask)
8080

8181
protected override Assembly Load(AssemblyName assemblyName)
8282
{
83+
// Always load libgit2sharp in the default context.
84+
// Something about the p/invoke done in that library with its custom marshaler
85+
// doesn't sit well with Core CLR 2.x.
86+
// See https://github.com/AArnott/Nerdbank.GitVersioning/issues/215 and https://github.com/dotnet/coreclr/issues/19654
87+
AssemblyLoadContext preferredContext = assemblyName.Name.Equals("libgit2sharp", StringComparison.OrdinalIgnoreCase) ? Default : this;
8388
string assemblyPath = Path.Combine(this.loaderTask.ManagedDllDirectory, assemblyName.Name) + ".dll";
8489
if (File.Exists(assemblyPath))
8590
{
86-
return LoadFromAssemblyPath(assemblyPath);
91+
return preferredContext.LoadFromAssemblyPath(assemblyPath);
8792
}
8893

8994
return Default.LoadFromAssemblyName(assemblyName);

0 commit comments

Comments
 (0)