Skip to content

Commit f84852a

Browse files
committed
Net Core - Assembly.GetEntryAssembly can return null when loaded from an unmanaged application
- Add null check and use currently assembly location to resolve libcef.dll The GetEntryAssembly method can return null when a managed assembly has been loaded from an unmanaged application. https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly?view=net-5.0
1 parent 1692c1b commit f84852a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

CefSharp.Core/Initializer.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ public static class Initializer
2727
[ModuleInitializer]
2828
internal static void ModuleInitializer()
2929
{
30-
var currentFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
30+
string currentFolder;
31+
32+
var executingAssembly = Assembly.GetEntryAssembly();
33+
//The GetEntryAssembly method can return null when a managed assembly has been loaded from an unmanaged application.
34+
//https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly?view=net-5.0
35+
if (executingAssembly == null)
36+
{
37+
currentFolder = Path.GetDirectoryName(typeof(Initializer).Assembly.Location);
38+
}
39+
else
40+
{
41+
currentFolder = Path.GetDirectoryName(executingAssembly.Location);
42+
}
43+
3144
var libCefPath = Path.Combine(currentFolder, "libcef.dll");
3245

3346
if (File.Exists(libCefPath))

0 commit comments

Comments
 (0)