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

System.DllNotFoundException: libzstd #15

Open
owenStarry opened this issue Sep 6, 2017 · 2 comments
Open

System.DllNotFoundException: libzstd #15

owenStarry opened this issue Sep 6, 2017 · 2 comments

Comments

@owenStarry
Copy link

When I used zstdnet in web applications, it throwed System.DllNotFoundException: libzstd. I review ed the loading native DLL's source code(ExternMethods class) , found a bug that set directory dll error in SetWinDllDirectory method,as follows:
var location = Assembly.GetExecutingAssembly().Location;
In web application, it will get temporary asp.net files directory, not the native dll directory.
I suggest the code modify following:
using System.Web;
var isWebApplication = false;
if(HttpContext.Current!=null){
isWebApplication = true;
}
var location = string.empty;
if(isWebApplication){
//get web application bin direcotry
location = $"{System.AppDomain.CurrentDomain.BaseDirectory}bin/";
}else{
location = Assembly.GetExecutingAssembly().Location;
}

@owenStarry
Copy link
Author

I found a better way to solve this problem,as following:
var location = GetBinPath();
public static string GetBinPath()
{
string baseDir = AppDomain.CurrentDomain.BaseDirectory;

        // Note RelativeSearchPath can be null even if the doc say something else; don't remove the check
        string searchPath = AppDomain.CurrentDomain.RelativeSearchPath ?? string.Empty;

        string relativeSearchPath = searchPath.Split(';').First();
        string binPath = Path.Combine(baseDir, relativeSearchPath);
        return binPath;
    }

@owenStarry
Copy link
Author

I finally modify SetWinDllDirectory method as following:
private static void SetWinDllDirectory()
{
var path = GetBinPath();
var platform = Environment.Is64BitProcess ? "x64" : "x86";
if (!SetDllDirectory(Path.Combine(path, platform)))
Trace.TraceWarning($"{nameof(ZstdNet)}: Failed to set DLL directory to '{path}'");
}

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

No branches or pull requests

1 participant