diff --git a/MathNet.Numerics.NativeProviders.sln b/MathNet.Numerics.NativeProviders.sln index 69f15233..141b7074 100644 --- a/MathNet.Numerics.NativeProviders.sln +++ b/MathNet.Numerics.NativeProviders.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30501.0 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5A0892FF-82CE-40FC-BCE1-73810C615F52}" ProjectSection(SolutionItems) = preProject @@ -97,18 +97,14 @@ Global {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Any CPU.Build.0 = Debug|Any CPU {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Win32.ActiveCfg = Debug|x86 - {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Win32.Build.0 = Debug|x86 - {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|x64.ActiveCfg = Debug|x64 - {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|x64.Build.0 = Debug|x64 + {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Win32.ActiveCfg = Debug|Any CPU + {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|x64.ActiveCfg = Debug|Any CPU {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Any CPU.ActiveCfg = Release|Any CPU {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Any CPU.Build.0 = Release|Any CPU {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Win32.ActiveCfg = Release|x86 - {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Win32.Build.0 = Release|x86 - {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|x64.ActiveCfg = Release|x64 - {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|x64.Build.0 = Release|x64 + {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Win32.ActiveCfg = Release|Any CPU + {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|x64.ActiveCfg = Release|Any CPU {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release-Signed|Any CPU.Build.0 = Release|Any CPU {3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release-Signed|Mixed Platforms.ActiveCfg = Release|Any CPU diff --git a/src/Numerics/Providers/NativeProviderLoader.cs b/src/Numerics/Providers/NativeProviderLoader.cs index c0c50511..3a8c2b5b 100644 --- a/src/Numerics/Providers/NativeProviderLoader.cs +++ b/src/Numerics/Providers/NativeProviderLoader.cs @@ -49,7 +49,7 @@ namespace MathNet.Numerics.Providers () => new Dictionary(StringComparer.OrdinalIgnoreCase) { {"x86", "x86"}, - {"AMD64", "amd64"}, + {"AMD64", "x64"}, {"IA64", "ia64"}, {"ARM", "arm"} }, @@ -115,6 +115,7 @@ namespace MathNet.Numerics.Providers public static Exception LastException { get; private set; } private static object staticLock = new Object(); + /// /// Load the native library with the given filename. /// @@ -125,15 +126,21 @@ namespace MathNet.Numerics.Providers if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName"); - lock(staticLock) + lock (staticLock) { IntPtr libraryHandle = IntPtr.Zero; if (NativeHandles.TryGetValue(fileName, out libraryHandle)) return true; - string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ArchDirectory, fileName); + if (string.IsNullOrEmpty(ArchDirectory)) + return false; + + // Look for the library in a acrhtecture directory under the current AppDomain's base directory or this assembly's directory + string path = Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), ArchDirectory, fileName); + if (!File.Exists(path)) + path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ArchDirectory, fileName); - if (string.IsNullOrEmpty(ArchDirectory) || !File.Exists(path)) + if (!File.Exists(path)) { // If the library isn't found within an architecture specific folder then return false // to allow normal P/Invoke searching behaviour when the library is called @@ -162,8 +169,16 @@ namespace MathNet.Numerics.Providers [SecurityCritical] private static class WindowsLoader { + public static IntPtr LoadLibrary(string fileName) + { + return LoadLibraryEx(fileName, IntPtr.Zero, LOAD_WITH_ALTERED_SEARCH_PATH); + } + + // Search for dependencies in the library's directory rather than the calling process's directory + const uint LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008; + [DllImport("kernel32", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto, SetLastError = true)] - public static extern IntPtr LoadLibrary(string fileName); + private static extern IntPtr LoadLibraryEx(string fileName, IntPtr reservedNull, uint flags); } [SuppressUnmanagedCodeSecurity] diff --git a/src/UnitTests/UnitTests-MKL.csproj b/src/UnitTests/UnitTests-MKL.csproj index 2430ead3..bbd73bbf 100644 --- a/src/UnitTests/UnitTests-MKL.csproj +++ b/src/UnitTests/UnitTests-MKL.csproj @@ -17,7 +17,7 @@ TRACE;NATIVE - ..\..\out\MKL\Windows\AnyCPU\ + ..\..\out\MKL\Windows\ ..\..\obj\MKL\Windows\x86\ ..\..\obj\MKL\Windows\x86\ true @@ -29,7 +29,7 @@ TRACE;DEBUG;NATIVE - ..\..\out\MKL\Windows\AnyCPU\ + ..\..\out\MKL\Windows\ ..\..\obj\MKL\Windows\x86\ ..\..\obj\MKL\Windows\x86\ false @@ -40,54 +40,6 @@ 1591 AnyCPU - - ..\..\out\MKL\Windows\x86\ - ..\..\obj\MKL\Windows\x86\ - ..\..\obj\MKL\Windows\x86\ - TRACE;NATIVE - true - 1591 - pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - - - true - ..\..\out\MKL\Windows\x86\ - ..\..\obj\MKL\Windows\x86\ - ..\..\obj\MKL\Windows\x86\ - TRACE;DEBUG;NATIVE - 1591 - full - x86 - prompt - MinimumRecommendedRules.ruleset - - - ..\..\out\MKL\Windows\x64\ - ..\..\obj\MKL\Windows\x64\ - ..\..\obj\MKL\Windows\x64\ - TRACE;NATIVE - true - 1591 - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - - - true - ..\..\out\MKL\Windows\x64\ - ..\..\obj\MKL\Windows\x64\ - ..\..\obj\MKL\Windows\x64\ - TRACE;DEBUG;NATIVE - 1591 - full - x64 - prompt - MinimumRecommendedRules.ruleset -