Skip to content

Commit

Permalink
Workaround Core CLR p/invoke load context bug
Browse files Browse the repository at this point in the history
Fixes #215
  • Loading branch information
AArnott committed Aug 25, 2018
1 parent 50f4029 commit 5e0e996
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/MSBuildExtensionTask/ContextAwareTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ internal CustomAssemblyLoader(ContextAwareTask loaderTask)

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

return Default.LoadFromAssemblyName(assemblyName);
Expand Down

0 comments on commit 5e0e996

Please sign in to comment.