NetCore - Initializer additional checks to locate libcef.dll

- When running from a library with no RuntimeIdentifier specified, check
  relative to CefSharp.Core.dll in runtimes folder
This commit is contained in:
Alex Maitland
2024-01-19 20:13:51 +10:00
parent fb24fd22e5
commit bbe7260fe8
+16 -1
View File
@@ -34,7 +34,7 @@ namespace CefSharp
//https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly?view=net-5.0
if (executingAssembly == null)
{
currentFolder = Path.GetDirectoryName(typeof(Initializer).Assembly.Location);
currentFolder = GetCefSharpCoreAssemblyLocation();
}
else
{
@@ -66,6 +66,16 @@ namespace CefSharp
var arch = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
var archFolder = $"runtimes\\win-{arch}\\native";
libCefPath = Path.Combine(currentFolder, archFolder, "libcef.dll");
if (!File.Exists(libCefPath))
{
// For cases where the library is dynamically loaded and no RuntimeIdentifier
// specified, attempt to locate libcef.dll next to CefSharp.Core.dll
currentFolder = GetCefSharpCoreAssemblyLocation();
libCefPath = Path.Combine(currentFolder, archFolder, "libcef.dll");
}
if (File.Exists(libCefPath))
{
LibCefLoaded = NativeLibrary.TryLoad(libCefPath, out IntPtr handle);
@@ -86,5 +96,10 @@ namespace CefSharp
}
}
}
private static string GetCefSharpCoreAssemblyLocation()
{
return Path.GetDirectoryName(typeof(Initializer).Assembly.Location);
}
}
}