Creating CefSharp browser component in a hydra plugin throws error


(EvgenyK) #12

you can attach it here or send directly to support@

for attaching here, use

(jpierce) #13 (97.8 KB)

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.


(EvgenyK) #14

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

Note: I’m Delphi guy only.

(jpierce) #15

Press the StartupBtn.

(EvgenyK) #16

I’ve exposed default AppDomain and am trying to test it with your sample…

already did. also I’ve updated your sample as

        public void Startup()
                web = new ChromiumWebBrowser();

but nothing happened: no errors in delphi and no errors in VS :frowning:

can you create plugin that works with .NET host as expected, pls ?

(jpierce) #17

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.

(jpierce) #18

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. :smiley:

(antonk) #19


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.


(EvgenyK) #20

Drop email to support@ .
we will send fix to you

(jpierce) #21

Email sent.

(Santiago Burbano) #22

Hi there,
we ran into the same problem.
Did you ever find a solution?
Could you get the Visual Plugin with the Chromium component to work?



I see there is a contructor for THYManagedModule which I had not noticed before:

constructor Create(aFileName: string; const aDefaultDomain: THYClrDomain); reintroduce; overload;

I will try using hcdDefaultDomain. This might do the trick.

(EvgenyK) #23

you are right.
also you can use:

procedure TMainForm.FormCreate(Sender: TObject);
      CefSharpPluginInstance, GuestPanel);

(Santiago Burbano) #24


using ‘hcdDefaultDomain’ to load our managed module did the trick :slight_smile:

Now we have the chromium based CEF Sharp html viewer running inside our Delphi App.

One problem we have not been able to figure out though.

If we display an html document in Delphi (using the Hydra Visual Plugin) the background shows up gray.

However if we display the SAME html document in .NET directly without using Hydra the background is white.
If we open that HTML document in Chrome the background is white as well. Actually the html body background is not set.

So it seems that the Delphi Visual Plugin somehow changes the background of the WPF control to be gray (default control color). We did set the background for the Delphi TPanel which serves as the plugin host to white, but this did not change anything.

Any ideas?

*** EDIT ***

Figured it out. When no html background color is specified the Html Viewer is transparent, meaning that the background color of the control will show. We just set the background color of the WPF Plugin to white and got the behaviour we needed.

(Sravanthi Mallikarjuna) #25

I was able to get this working as well using the solution above but we’re having troubles with dealing with multiple instances of the visual plugin because of the appDomain story above.

So, in our app, the form that’s hosting the visual plugin and chromium browser inside of it is actually an MDI child form, which means that you can have multiple instances of it, which means that you can have multiple instances of the web browser and the visual plugin.
When we close the MDI child form we’re also unloading the plugin, but as soon as you close all of the instances of that MDI Child form, and try to create a new instance of the form the web browser in the visual plugin will not work. We’re not seeing any errors, but the plugin content looks just broken( frozen).

Any ideas on how to deal with this use case?


(antonk) #26

You can try to create 1 additional instance of plugin on load and do not unload it even when all MDI Child forms are closed.

I can only guess, but it seems that the component you are using is a kind of special one (f.e. for some reason it cannot work in a non-default .NET AppDomain), so when you unload the last one of its instances it stops its event queue and never starts it again.

(Sravanthi Mallikarjuna) #27

That’s not a bad idea. I’ll try that.
Yeah, I’m using the same CEF Sharp web browser mentioned above which apparently needs to be loaded into the default appDomain. So, that’s kinda the struggle, as all of these instances are being loaded into the same appDomain.
Btw, @Santiago_Burbano, which CEF Sharp version of the plugin are you using and also which type of project is your visual plugin that’s hosting it, is it WPF or WinForms?

Not sure if that matters, but apparently CEF Sharp browser inside of the WinForms performs better.

(antonk) #28

WinForms plugins require less resources and are more friendly to cross-patform marshalling.

(Santiago Burbano) #29

we are using WPF.
This is from our packages.config file:

  <package id="cef.redist.x64" version="3.2883.1552" targetFramework="net452" />
  <package id="cef.redist.x86" version="3.2883.1552" targetFramework="net452" />
  <package id="CefSharp.Common" version="55.0.0" targetFramework="net452" />
  <package id="CefSharp.OffScreen" version="55.0.0" targetFramework="net452" />
  <package id="CefSharp.Wpf" version="55.0.0" targetFramework="net452" />

We have not updated that NuGet Package in a while. Current version is working fine for us.

(Sravanthi Mallikarjuna) #30

Thanks. Btw, how are you dealing with this issue of having to load the plugin into the default appdomain and the fact that you can’t unload the plugin hosting the browser?
Also, do you have a case where you can have multiple instances of the plugin running in your delphi app?


(Santiago Burbano) #31

we don’t need to unload that plugin and we have not needed to have multiple instances of that plugin either.