Skip to content

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

Closed

Description

@bwknight877

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()```

Activity

  1. bwknight877 commented on Nov 28, 2016

    @bwknight877
    Author
  2. mclang commented on Dec 7, 2016

    @mclang

    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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions