88using System . Reflection ;
99using System . Runtime . InteropServices ;
1010using System . Text ;
11- using System . Web ;
1211
1312namespace OpenCvSharp
1413{
@@ -28,7 +27,7 @@ public sealed class WindowsLibraryLoader
2827 public static WindowsLibraryLoader Instance { get { return instance ; } }
2928
3029 #endregion
31-
30+
3231 /// <summary>
3332 /// The default base directory name to copy the assemblies too.
3433 /// </summary>
@@ -53,7 +52,7 @@ public sealed class WindowsLibraryLoader
5352 /// <summary>
5453 /// Used as a sanity check for the returned processor architecture to double check the returned value.
5554 /// </summary>
56- private readonly Dictionary < string , int > processorArchitectureAddressWidthPlatforms =
55+ private readonly Dictionary < string , int > processorArchitectureAddressWidthPlatforms =
5756 new Dictionary < string , int > ( StringComparer . OrdinalIgnoreCase )
5857 {
5958 { "x86" , 4 } ,
@@ -65,8 +64,8 @@ public sealed class WindowsLibraryLoader
6564 /// <summary>
6665 /// Additional user-defined DLL paths
6766 /// </summary>
68- public List < string > AdditionalPaths { get ; private set ; }
69-
67+ public List < string > AdditionalPaths { get ; private set ; }
68+
7069 private readonly object syncLock = new object ( ) ;
7170
7271 /// <summary>
@@ -114,7 +113,7 @@ public void LoadLibrary(string dllName, IEnumerable<string> additionalPaths = nu
114113
115114 if ( additionalPaths == null )
116115 additionalPaths = new string [ 0 ] ;
117-
116+
118117 try
119118 {
120119 lock ( syncLock )
@@ -131,8 +130,8 @@ public void LoadLibrary(string dllName, IEnumerable<string> additionalPaths = nu
131130 // Try loading from user-defined paths
132131 foreach ( string path in additionalPaths )
133132 {
134- baseDirectory = Path . GetDirectoryName ( path ) ;
135- dllHandle = LoadLibraryInternal ( dllName , baseDirectory , processArch ) ;
133+ // baseDirectory = Path.GetFullPath (path);
134+ dllHandle = LoadLibraryRaw ( dllName , path ) ;
136135 if ( dllHandle != IntPtr . Zero ) return ;
137136 }
138137
@@ -170,10 +169,10 @@ public void LoadLibrary(string dllName, IEnumerable<string> additionalPaths = nu
170169 // include process detection warnings
171170 errorMessage . AppendFormat ( "\r \n Warnings: \r \n {0}" , processArch . WarningText ( ) ) ;
172171 }
173- throw new LoadLibraryException ( errorMessage . ToString ( ) ) ;
172+ throw new Exception ( errorMessage . ToString ( ) ) ;
174173 }
175174 }
176- catch ( LoadLibraryException e )
175+ catch ( Exception e )
177176 {
178177 Trace . TraceError ( e . Message ) ;
179178 }
@@ -222,11 +221,19 @@ private ProcessArchitectureInfo GetProcessArchitecture()
222221
223222 private IntPtr LoadLibraryInternal ( string dllName , string baseDirectory , ProcessArchitectureInfo processArchInfo )
224223 {
225- IntPtr libraryHandle = IntPtr . Zero ;
224+ // IntPtr libraryHandle = IntPtr.Zero;
226225 var platformName = GetPlatformName ( processArchInfo . Architecture ) ;
227226 var expectedDllDirectory = Path . Combine (
228227 Path . Combine ( baseDirectory , DllDirectory ) , platformName ) ;
229- var fileName = FixUpDllFileName ( Path . Combine ( expectedDllDirectory , dllName ) ) ;
228+ //var fileName = FixUpDllFileName(Path.Combine(expectedDllDirectory, dllName));
229+
230+ return LoadLibraryRaw ( dllName , expectedDllDirectory ) ;
231+ }
232+
233+ private IntPtr LoadLibraryRaw ( string dllName , string baseDirectory )
234+ {
235+ IntPtr libraryHandle = IntPtr . Zero ;
236+ var fileName = FixUpDllFileName ( Path . Combine ( baseDirectory , dllName ) ) ;
230237
231238 if ( File . Exists ( fileName ) )
232239 {
@@ -250,15 +257,15 @@ private IntPtr LoadLibraryInternal(string dllName, string baseDirectory, Process
250257 else
251258 {
252259 Trace . TraceError (
253- "Failed to load native library \" {0}\" .\r \n Check windows event log." ,
260+ "Failed to load native library \" {0}\" .\r \n Check windows event log." ,
254261 fileName ) ;
255262 }
256263 }
257264 catch ( Exception e )
258265 {
259266 var lastError = Marshal . GetLastWin32Error ( ) ;
260267 Trace . TraceError (
261- "Failed to load native library \" {0}\" .\r \n Last Error:{1}\r \n Check inner exception and\\ or windows event log.\r \n Inner Exception: {2}" ,
268+ "Failed to load native library \" {0}\" .\r \n Last Error:{1}\r \n Check inner exception and\\ or windows event log.\r \n Inner Exception: {2}" ,
262269 fileName , lastError , e ) ;
263270 }
264271 }
0 commit comments