I’ve got a pretty simple hydra plugin developed in C#. The core of the plugin looks like this:
[Plugin, VisualPlugin, NeedsManagedWrapper(typeof(CustomPluginWrapper))]
public partial class CefSharpPlugin : RemObjects.Hydra.WPF.VisualPlugin, ICefSharpPlugin
{
public void ProcessMessage(string str)
{
System.Diagnostics.Debug.WriteLine(str);
}
public CefSharpPlugin()
{
InitializeComponent();
}
ChromiumWebBrowser web;
public void Startup()
{
web = new ChromiumWebBrowser();
}
public void Shutdown()
{
web = null;
}
}
The xaml is just an empty hydra:VisualPlugin element and a Background color set so I can tell the plugin is loading.
I have CustomPluginWrapper all set up and working fine and I have a Delphi host app that loads the plugin and can call ProcessMessage without any problems. It gets the background color so the visual plugin loaded. I have also created visual plugins before that worked fine.
The problematic part comes when I call the Startup, which creates a new CefSharp ChromiumWebBrowser component. This causes the hydra plugin to blow up, throwing:
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: cefsharphostxe2.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 55674119
Problem Signature 04: mscorlib
Problem Signature 05: 4.0.30319.18444
Problem Signature 06: 52717edc
Problem Signature 07: 3de7
Problem Signature 08: 1f
Problem Signature 09: System.ArgumentException
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
This happens in both a Delphi 2007 and Xe2 host app. All my testing is on Win32, btw.
I’ve used CefSharp’s ChromiumWebBrowser just fine outside of Hydra. I wonder what it is that could be causing Hydra problems.
CefSettings a = new CefSettings();
CefSharp.Wpf.RenderingEventArgs b = new CefSharp.Wpf.RenderingEventArgs(null);
and those go off without an error, and I can see in procexp that the exe is loading all the same CefSharp.dll, CefSharp.Core.dll and CefSharp.Wpf.dll that it should be.
It’s just creating the browser object that causes it to blow.
I don’t think it’s app domains, we run hydra in the main app domain afaik; I suggest you open your Delphi .exe as a host for your plugin, run it and break on ArgumentException, see what the exception says.
System.ArgumentException occurred
Message: A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Cannot pass a GCHandle across AppDomains.
Googling that is how I managed to get to that report about it not working as a plugin. I’m not much of an expert of .NET stuff (or CEF, for that matter).
Application: CefSharpHostXe2.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException
Stack:
at System.Runtime.InteropServices.GCHandle.InternalCheckDomain(IntPtr)
at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr)
at <Module>.gcroot<System::Action ^>..P$AAVAction@System@@(gcroot<System::Action ^>*)
at <Module>.CefSharp.CefSharpApp.OnContextInitialized(CefSharp.CefSharpApp*)
I have one. Do you want me to zip it and post it somewhere or mail it? Don’t see any way to attach on this forum. I could also just post the MainWindow.xaml.cs for the plugin and the form source for the Delphi app.
Ah, there it is! I flew over those icons but somehow missed it.
I’ve included both the Delphi Xe2 host and the CefSharp plugin. You’ll need to add the nuget package for CefSharp (the current version). I’m knew to the C# thing, so I’m not sure if I should include the actual packages dir or not. I left it off because you can just add them. If you need me to do it different, just explain in small words.
I’ve launched your testcase and saw colored panel after host was started. should plugin do something else?
pressing startup button doesn’t change situation
What version of Delphi are you testing it against? I’ve tested against Delphi 2007 and Xe2 (that’s what we have licenses for).
Also, what do you mean “can you create plugin that works with .NET host as expected, pls ?” Are you asking me to create a .NET HOST instead of a Delphi host? Is there actually any page or help file to explain how to do that? I’m trying and struggling. The instructions for creating a Delphi host are pretty clear but there’s several things that are tripping me up in building a .NET one.
Also, what does this mean? Is that something I am supposed to do? I have to be honest and say I have no idea if you’re talking about Delphi, .NET, or what. It’s all beyond my current understanding.
In short words (and with very less details):
Surely term ‘default AppDomain’ sounds very strange when applied to a Win32 Delphi app.
When .NET runtime gets loaded into a Delphi app (to later load the .NET plugins) this .NET runtime creates a default Application Domain. But by default all .NET plugins are (were) loaded into a separate specially created AppDomain. This separate AppDomain is used because plugins loaded into the default AppDomain cannot be unloaded (this is .NET restriction, not Hydra’s one).
Unability to unload .NET plugins vs using the default AppDomain is a very significant tradeoff.So it will be (probably) controlled by a separate host option.