static void ExtractNativeDLL(string name, string bitness)
{
string location;
// Select different default location when the process is hosted by IIS
if (HostingEnvironment.IsHosted)
{
location = HostingEnvironment.MapPath(@"~\bin\");
}
else
{
location = Assembly.GetExecutingAssembly().Location;
}
Debug.WriteLine(String.Format("Location: {0}", location));
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
string clientPrefix = "ScalienClient.NativeDLL";
string separator = "-";
string fileName = string.Join(separator, new string[] {clientPrefix, bitness, fvi.FileVersion});
// First try to load the DLL from the default directory
if (TryLoadDLL(name))
return;
// Then try to load the DLL from the directory of the executing assembly
string dirName = Path.Combine(Path.GetDirectoryName(location), fileName);
string dllPath = TryExtractDLL(dirName, name, bitness);
if (dllPath != null)
{
if (TryLoadDLL(dllPath))
return;
}
// Finally try to load the DLL from the temp directory
string tempDirName = Path.Combine(Path.GetTempPath(), fileName);
dllPath = TryExtractDLL(tempDirName, name, bitness);
if (dllPath != null)
{
if (TryLoadDLL(dllPath))
return;
}
Debug.Assert(false, "Unable to load library " + dllPath);
}