Skip to content

Commit 01d775a

Browse files
committed
Core - Add BrowserSubprocess.SelfHost.Main
Can be used to self host the browser SubProcess Fixes build errors, the Net Core implementation is now renamed from MainNetCore to Main Issue #3197
1 parent 6e4e415 commit 01d775a

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

CefSharp.BrowserSubprocess.Core/BrowserSubprocessExecutable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace CefSharp
4141
/// with a value of -1. If called for a recognized secondary process it will block until the process should exit
4242
/// and then return the process exit code.
4343
/// </returns
44-
static int MainNetCoreSelfHost(array<String^>^ args)
44+
static int MainSelfHost(array<String^>^ args)
4545
{
4646
auto subProcess = gcnew BrowserSubprocessExecutable();
4747
return subProcess->Main(args, nullptr);

CefSharp.Core.RefAssembly/CefSharp.Core.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ namespace CefSharp.BrowserSubprocess
334334
public partial class SelfHost
335335
{
336336
public SelfHost() { }
337-
public static int MainNetCore(string[] args) { throw null; }
337+
public static int Main(string[] args) { throw null; }
338338
}
339339
}
340340
namespace CefSharp.Internals

CefSharp.Core/BrowserSubprocess/SelfHost.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
using namespace System;
99
using namespace System::IO;
10-
using namespace System::Runtime::Loader;
1110
using namespace CefSharp;
1211

1312
namespace CefSharp
1413
{
1514
namespace BrowserSubprocess
1615
{
17-
int SelfHost::MainNetCore(array<String^>^ args)
16+
int SelfHost::Main(array<String^>^ args)
1817
{
1918
auto type = CommandLineArgsParser::GetArgumentValue(args, CefSharpArguments::SubProcessTypeArgument);
2019

@@ -27,11 +26,15 @@ namespace CefSharp
2726
}
2827

2928
auto browserSubprocessDllPath = Path::Combine(Path::GetDirectoryName(SelfHost::typeid->Assembly->Location), "CefSharp.BrowserSubprocess.Core.dll");
30-
auto browserSubprocessDll = AssemblyLoadContext::Default->LoadFromAssemblyPath(browserSubprocessDllPath);
29+
#ifdef NETCOREAPP
30+
auto browserSubprocessDll = System::Runtime::Loader::AssemblyLoadContext::Default->LoadFromAssemblyPath(browserSubprocessDllPath);
31+
#else
32+
auto browserSubprocessDll = System::Reflection::Assembly::LoadFrom(browserSubprocessDllPath);
33+
#endif
3134
auto browserSubprocessExecutableType = browserSubprocessDll->GetType("CefSharp.BrowserSubprocess.BrowserSubprocessExecutable");
3235
auto browserSubprocessExecutable = Activator::CreateInstance(browserSubprocessExecutableType);
3336

34-
auto mainMethod = browserSubprocessExecutableType->GetMethod("MainNetCoreSelfHost", System::Reflection::BindingFlags::Static | System::Reflection::BindingFlags::Public);
37+
auto mainMethod = browserSubprocessExecutableType->GetMethod("MainSelfHost", System::Reflection::BindingFlags::Static | System::Reflection::BindingFlags::Public);
3538
auto argCount = mainMethod->GetParameters();
3639

3740
auto methodArgs = gcnew array<Object^>(1);

CefSharp.Core/BrowserSubprocess/SelfHost.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace CefSharp
3232
/// with a value of -1. If called for a recognized secondary process it will block until the process should exit
3333
/// and then return the process exit code.
3434
/// </returns
35-
static int MainNetCore(array<String^>^ args);
35+
static int Main(array<String^>^ args);
3636

3737
};
3838
}

CefSharp.WinForms.Example/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public class Program
1717
[STAThread]
1818
public static int Main(string[] args)
1919
{
20-
const bool selfHostSubProcess = true;
20+
const bool selfHostSubProcess = false;
2121

2222
Cef.EnableHighDPISupport();
2323

2424
//NOTE: Using a simple sub processes uses your existing application executable to spawn instances of the sub process.
2525
//Features like JSB, EvaluateScriptAsync, custom schemes require the CefSharp.BrowserSubprocess to function
2626
if (selfHostSubProcess)
2727
{
28-
var exitCode = CefSharp.BrowserSubprocess.SelfHost.MainNetCore(args);
28+
var exitCode = CefSharp.BrowserSubprocess.SelfHost.Main(args);
2929

3030
if (exitCode >= 0)
3131
{

0 commit comments

Comments
 (0)