Skip to content

Commit

Permalink
Fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees committed Mar 16, 2022
1 parent 7808cff commit 73fe0b2
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions TesseractOCR/InteropDotNet/LibraryLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using System.IO;
using System.Reflection;
using TesseractOCR.Helpers;
using TesseractOCR.Loggers;
using File = System.IO.File;

// ReSharper disable UnusedMember.Global
Expand Down Expand Up @@ -103,8 +102,11 @@ public IntPtr LoadLibrary(string fileName, string platformName = null)
platformName = SystemManager.GetPlatformName();

Logger.LogInformation($"Current platform is {platformName}");

var dllHandle = CheckCodeBase(fileName, platformName);

var dllHandle = CheckExecutingAssemblyDomain(fileName, platformName);
if (dllHandle == IntPtr.Zero)
dllHandle = CheckExecutingAssemblyDomain(fileName, platformName);

if (dllHandle == IntPtr.Zero)
dllHandle = CheckCurrentAppDomain(fileName, platformName);
Expand All @@ -126,6 +128,24 @@ public IntPtr LoadLibrary(string fileName, string platformName = null)
}
#endregion

#region CheckCodeBase
private IntPtr CheckCodeBase(string fileName, string platformName)
{
var assemblyLocation = Assembly.GetExecutingAssembly().GetName().CodeBase;

if (string.IsNullOrEmpty(assemblyLocation))
{
Logger.LogInformation("Code base was empty");
return IntPtr.Zero;
}

assemblyLocation = assemblyLocation.Substring(8);
var baseDirectory = Path.GetDirectoryName(assemblyLocation);
return InternalLoadLibrary(baseDirectory, platformName, fileName);
}
#endregion


#region CheckExecutingAssemblyDomain
private IntPtr CheckExecutingAssemblyDomain(string fileName, string platformName)
{
Expand Down

0 comments on commit 73fe0b2

Please sign in to comment.