Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Unable to load native DLL if path contains %2F #1389

Closed
bwknight877 opened this issue Nov 23, 2016 · 2 comments
Closed

Unable to load native DLL if path contains %2F #1389

bwknight877 opened this issue Nov 23, 2016 · 2 comments

Comments

@bwknight877
Copy link

libgit2sharp is failing to load the native DLLs if the directory path contains %2F

How did I get in this state? Our Jenkins build checks out GitHub repositories with the branch name in them. In my case, the branch name was in the format features/dev10 with a forward slash in the branch name.

That branch path in Windows ends up being C:\jenkins\workspace\features%2Fdev10\

This failure can be easily reproduced in libgit2sharp by setting the Output Path of LibGit2Sharp.Tests to busted%2Fdirectory\

I've tracked the problem down to GlobalSettings.cs, lines 22-31:

static GlobalSettings()
{
    if (Platform.OperatingSystem == OperatingSystemType.Windows)
    {
        string managedPath = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;
        nativeLibraryPath = Path.Combine(Path.Combine(Path.GetDirectoryName(managedPath), "lib"), "win32");
    }

    registeredFilters = new Dictionary<Filter, FilterRegistration>();
}

It looks like creating a Uri out of the current path turns the legit %2F in the directory name back into a forward slash.

After that, the DLL load mechanism fails to find the native git2.dll in NativeMethods.cs because it adds an invalid directory to the PATH environment variable

I hit this issue using Cake and the GitVersion tool which in turn uses libgit2sharp

In the meantime, I might be able to add the DLL directory to my PATH environment variable before calling GitVersion as a workaround. Also not putting forward slashes in the git branch names will work around this issue with Jenkins putting the %2F in the directory name.

Stack trace below

14:35:43 Unhandled Exception: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'git2-381caf5': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
14:35:43    at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
14:35:43    at LibGit2Sharp.Core.NativeMethods.LibraryLifetimeObject..ctor()
14:35:43    at LibGit2Sharp.Core.NativeMethods..cctor()
14:35:43    --- End of inner exception stack trace ---
14:35:43    at LibGit2Sharp.Core.NativeMethods.RemoveHandle()
14:35:43    at LibGit2Sharp.Core.NativeMethods.LibraryLifetimeObject.Finalize()```

@bwknight877
Copy link
Author

it looks like EscapedCodeBase does not correctly escape the path with % in it

http://stackoverflow.com/a/28319367/28659

@mclang
Copy link

mclang commented Dec 7, 2016

I have the same problem, linked above.
Should I post my output or something like

ldd packages/GitVersion.CommandLine/tools/lib/linux/x86_64/libgit2-baa87df.so

here also?

Sorry, forgot to mention that my full path to the library is like:

~/Projects/GenerateDriveEvents/packages/GitVersion.CommandLine/tools/lib/linux/x86_64/libgit2-baa87df.so

So maybe my problem with GitVersion using LibGit2 is different...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants