Skip to content
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

NativeMethods.ResolveDll: Avoid exceptions #1741

Merged
merged 1 commit into from
Nov 20, 2019
Merged

NativeMethods.ResolveDll: Avoid exceptions #1741

merged 1 commit into from
Nov 20, 2019

Conversation

qmfrederik
Copy link
Contributor

On .NET Core 3.0, LibGit2Sharp registers a per-assembly resolver using via NativeLibrary.SetDllImportResolver.

The per-assembly resolver is the first attempt to resolve native library loads initiated by an assembly and takes precedence over other mechanisms, such as AssemblyLoadContext.

The current implementation throws an exception if the {assemblyDirectory}/runtimes directory does not exist. In that case, the native load mechanism aborts, and AssemblyLoadContext never gets a chance to locate the native library.

This PR adds a Directory.Exists check to avoid that exception. ResolveDll will return IntPtr.Zero, and the AssemblyLoadContext is invoked next.

@qmfrederik
Copy link
Contributor Author

/cc @bording @tmds @AArnott . This should fix NB.GV on Ubuntu 19.04 x64

@bording bording merged commit 58410d5 into libgit2:master Nov 20, 2019
@bording
Copy link
Member

bording commented Nov 20, 2019

This is now on nuget.org as 0.27.0-preview-0034.

@qmfrederik qmfrederik deleted the fixes/resolve-dll-no-throw branch November 20, 2019 22:57
@qmfrederik
Copy link
Contributor Author

@bording Awesome, thanks!

@robertcoltheart
Copy link

Can this be either a) implemented in the 0.26 maintenance branch and released to Nuget as 0.26.3, or b) release 0.27.0 soon? We're struggling with this over here: GitTools/GitVersion#1852

@bording
Copy link
Member

bording commented May 4, 2020

Given the other work going on to try to improve the overall native binary scenario, I don't think we're at a point where we'd want to do another non-preview release yet.

TimoWolters added a commit to offis/lotsen-app that referenced this pull request Aug 12, 2021
The prerelease version should be able to handle missing dlls better than the official release based on libgit2/libgit2sharp#1741
TimoWolters added a commit to offis/lotsen-app that referenced this pull request Aug 12, 2021
commit d36a0a6ede6f257b1bc2b518ba82c61888ede219
Author: Timo Wolters <[email protected]>
Date:   Thu Aug 12 14:14:12 2021 +0200

    Update FileConfigurationStorage.cs

    The default configuration will be returned instead of throwing an exception. This should help make the application more resilient during startup.

commit deabce5
Author: Timo Wolters <[email protected]>
Date:   Thu Aug 12 13:44:19 2021 +0200

    Updating to LibGit2Sharp Prelease

    The prerelease version should be able to handle missing dlls better than the official release based on libgit2/libgit2sharp#1741

commit 98808bc
Author: Timo Wolters <[email protected]>
Date:   Thu Aug 12 12:59:09 2021 +0200

    Fixed issues with failing integration tests. Enabled integration tests in Github Actions again.
    Bugfix: Integration tests will no longer execute in parallel to avoid accessing shared resources.
    Bugfix: Fixed an issue with misleading messages during initial setup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants