-
Notifications
You must be signed in to change notification settings - Fork 910
Closed
Description
When using libgit2sharp from within LinqPad via NuGet, loading the native binary does not work as intended. The executing assembly usually lies somewhere "AppData\Local\Temp\LINQPad\whatever" while all referenced libraries lie elsewhere. CodeBase seems unset for the executing assembly. Thus the type initializer of NativeMethods fails put the correct location into the path:
static NativeMethods()
{
if (!IsRunningOnLinux())
{
string originalAssemblypath = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;
string currentArchSubPath = "NativeBinaries/" + ProcessorArchitecture;
string path = Path.Combine(Path.GetDirectoryName(originalAssemblypath), currentArchSubPath);
const string pathEnvVariable = "PATH";
Environment.SetEnvironmentVariable(pathEnvVariable,
String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", path, Path.PathSeparator, Environment.GetEnvironmentVariable(pathEnvVariable)));
}
// See LibraryLifetimeObject description.
lifetimeObject = new LibraryLifetimeObject();
}
A workaround is to add the correct path with EnvironMent.SetEnvironmentVariable at application start/composition root which seems a bit odd as it may break when updateing via nuget once again (see: http://stackoverflow.com/a/18867945/303290 ).