bp74 / Zstandard.Net

A Zstandard wrapper for .Net
Other
135 stars 26 forks source link

Incorrect path to native assembly when running under ASP.NET #19

Open LordBenjamin opened 4 years ago

LordBenjamin commented 4 years ago

Expected path to be D:\site\app\bin\x64\libzstd.dll

Actual path reported: D:\local\Temporary ASP.NET Files\service\413c8295\f1e75485\assembly\dl3\62e9e505\95643d38_7883d501\x64\libzstd.dll

Caused by ASP.NET shadow copying managed DLLs, but not unmanaged DLLs.

See https://stackoverflow.com/questions/6855924/third-party-dll-cant-find-its-dependencies-in-asp-net-mvc-project. Possibly needs to be solved at application level.

LordBenjamin commented 4 years ago

Worked around using

string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Process);

string nativePath = Path.Combine(
    AppDomain.CurrentDomain.RelativeSearchPath,
    Environment.Is64BitProcess ? "x64" : "x86");

Environment.SetEnvironmentVariable("Path", nativePath + ";" + path, EnvironmentVariableTarget.Process);

Note that this causes file locking issues if you try to update an ASP.NET site by overwriting the files - ideally need to shadow copy the native dependency.