Skip to content

Commit f919d71

Browse files
authored
Merge pull request #216 from AArnott/fix215
Workaround/fix for libgit2sharp custom marshal type cast failure
2 parents dfd2c88 + 7bf53d5 commit f919d71

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
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);

src/Nerdbank.GitVersioning.Tasks/GetBuildVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ protected override bool ExecuteInner()
247247
}
248248
catch (ArgumentOutOfRangeException ex)
249249
{
250-
Log.LogErrorFromException(ex);
250+
this.Log.LogErrorFromException(ex);
251251
return false;
252252
}
253253
}

0 commit comments

Comments
 (0)