Creating CefSharp browser component in a hydra plugin throws error

Email sent.

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?

Thanks!

** EDIT

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.

you are right.
also you can use:

procedure TMainForm.FormCreate(Sender: TObject);
begin
  ModuleManager.LoadModules(hcdDefaultDomain);
  ModuleManager.CreateVisualPlugin('netedgesolutions.CefSharpPlugin',
      CefSharpPluginInstance, GuestPanel);
end;

@EvgenkyK

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.

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?

Thanks,

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.

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.

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

@Sravanthi_Mallikarju
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.

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?

Thanks

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