You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
}
The text was updated successfully, but these errors were encountered:
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;
}
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}'");
}
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;
}
The text was updated successfully, but these errors were encountered: