CEF in .NET5 in a DLL

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

CEF in .NET5 in a DLL

Postby TedGCI » Mon Nov 22, 2021 11:21 am

I am trying to get CEF (In Visual Studio 2019) to run in a .NET5 (core) dll. It works perfectly in a .NET5 exe. But when I change over to a dll, the files needed aren't copied. And even when I do copy them the browser crashes. When I use .NET framework 4.7 in a dll it works fine.
So the question is has anyone here successfully run CEF in a .NET dll?
Also why don't the support files copy correctly their directories in a Visual Studio solution.
I am so close to making it work, but it just keeps dying on me.
Any help or insight would be greatly appreciated.
Thanks
TedGCI
Techie
 
Posts: 14
Joined: Mon Nov 22, 2021 11:09 am

Re: CEF in .NET5 in a DLL

Postby amaitland » Mon Nov 22, 2021 2:17 pm

Which CEF wrapper are you using?
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: CEF in .NET5 in a DLL

Postby TedGCI » Mon Nov 22, 2021 2:37 pm

amaitland wrote:Which CEF wrapper are you using?

I believe the answer you are looking for it CefSharp.Winforms.NETCore.
TedGCI
Techie
 
Posts: 14
Joined: Mon Nov 22, 2021 11:09 am

Re: CEF in .NET5 in a DLL

Postby amaitland » Mon Nov 22, 2021 2:59 pm

The default behaviour for .Net 5/6 library projects is that Nuget references aren't copied locally. This is not a CefSharp specific behaviour. You need to set EnableDynamicLoading = true in your project file.

https://docs.microsoft.com/en-us/dotnet ... micloading

https://docs.microsoft.com/en-us/dotnet ... in-support has other background information if you are trying to create a plugin.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: CEF in .NET5 in a DLL

Postby TedGCI » Mon Nov 22, 2021 6:05 pm

Thank you,
What is confusing is the exe works perfectly, copies everything properly etc., but then I try a dll and place all the files in the .dll directory it tries to run but the memory pops up from 16mb to 170mb as soon as it runs the CefIntialize(settings), where in the exe it goes to about 30mb. Then it complains that I need .Net to use this.
I will try your suggestion.
TedGCI
Techie
 
Posts: 14
Joined: Mon Nov 22, 2021 11:09 am

Re: CEF in .NET5 in a DLL

Postby TedGCI » Mon Nov 22, 2021 7:20 pm

I tried your suggestion and the files are being copied. BUT the browser doesn't know where they are so I started copying them to the output folder and things still don't work.
I looked and have not found where the "CefSettings.BrowserSubprocessPath" is set, or how I can set them.
Any clue would be very welcome. Or at least where the documentation is found for this stuff.
ALSO when I copy the CefSharp.BrowserSubprocess.exe to the directory it complains about it runs but give me the message "To run this application, you must install .NET Core. Would you like to download it now?" When you hit yes, it take you to the download page. I have loaded both x86 and x64 versions (this it an x86). Unless there is some other .NET it is looking for.
Thanks.
Ted
TedGCI
Techie
 
Posts: 14
Joined: Mon Nov 22, 2021 11:09 am

Re: CEF in .NET5 in a DLL

Postby amaitland » Mon Nov 22, 2021 9:53 pm

I tried your suggestion and the files are being copied. BUT the browser doesn't know where they are so I started copying them to the output folder and things still don't work.


What do you mean by the browser doesn't know where they are?

Are you creating a plugin? What is your project structure? Remember I've never seen your application so I only know that you are using CefSharp in a library, nothing about what you are doing with the library.

See https://github.com/cefsharp/CefSharp/wi ... ersettings for setting browser sub process path.

See also https://github.com/cefsharp/CefSharp/issues/3407 if you are publishing a self contained app.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: CEF in .NET5 in a DLL

Postby TedGCI » Tue Nov 23, 2021 10:31 am

What I meant was the library didn't know where the files were like they did in the exe version. BUT I figured out how to get it right with CefLibraryHandle and BrowserSubprocessPath.
What I am doing is creating a c# dll that uses chromiumBrowser to run an HTML casino game. This dll is consumed by a C++ Casino Gaming Engine that handles the I/O, buttons, candles , bill validators, printers, communications with accounting systems etc.
The customer bought a math engine dll that was written in .NET5, and getting anything to consume a .NET5 other than .NET5 is a nightmare.
So I said I would try to get a .NET5 dll working that used the chromium browser. I got an exe working with little trouble. But when I changed it to a dll it changed they way it used the files.
With your help I was able to get it to copy the files to the same place as the exe. Then I got them pointing at the correct place.
Now the only issue I have is the exe uses 30mb of memory and the dll (which is the exact same code) uses 185mb of memory.
Any clues on that??
Thanks,
Ted
TedGCI
Techie
 
Posts: 14
Joined: Mon Nov 22, 2021 11:09 am

Re: CEF in .NET5 in a DLL

Postby amaitland » Wed Nov 24, 2021 10:43 pm

Did you specify a RuntimeIdentifier so the directory structure was flattened?

- https://docs.microsoft.com/en-us/dotnet ... id-catalog
- https://github.com/cefsharp/CefSharp/bl ... me.txt#L10

BUT I figured out how to get it right with CefLibraryHandle and BrowserSubprocessPath.


That shouldn't be required under normal circumstances, specify a RuntimeIdentifier if you haven't already to only provide the dlls/resources for the relevant platform.

In .Net 5.0 you should use https://docs.microsoft.com/en-us/dotnet ... ew=net-6.0 instead of CefLibraryHandle

Now the only issue I have is the exe uses 30mb of memory and the dll (which is the exact same code) uses 185mb of memory.


`libcef.dll` is 130+mb this might be related to how you are loading the native library. Have you tested with a standard .Net project? Or just your own custom hosted CLR runtime.

Testing with https://github.com/amaitland/CefSharp.C ... ro.DemoApp and memory usage is as expected.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: CEF in .NET5 in a DLL

Postby TedGCI » Tue Dec 07, 2021 11:50 am

amaitland wrote:Did you specify a RuntimeIdentifier so the directory structure was flattened?

- https://docs.microsoft.com/en-us/dotnet ... id-catalog
- https://github.com/cefsharp/CefSharp/bl ... me.txt#L10

BUT I figured out how to get it right with CefLibraryHandle and BrowserSubprocessPath.


That shouldn't be required under normal circumstances, specify a RuntimeIdentifier if you haven't already to only provide the dlls/resources for the relevant platform.

In .Net 5.0 you should use https://docs.microsoft.com/en-us/dotnet ... ew=net-6.0 instead of CefLibraryHandle

Now the only issue I have is the exe uses 30mb of memory and the dll (which is the exact same code) uses 185mb of memory.


`libcef.dll` is 130+mb this might be related to how you are loading the native library. Have you tested with a standard .Net project? Or just your own custom hosted CLR runtime.

Testing with https://github.com/amaitland/CefSharp.C ... ro.DemoApp and memory usage is as expected.


Thanks, for the info. I will research your suggestions. And yes I did try it with a standard .net project and the memory usage was only about 30mb. I'm sure you are correct, but all I am doing is pointing to the library and not doing anything special.
TedGCI
Techie
 
Posts: 14
Joined: Mon Nov 22, 2021 11:09 am

Next

Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 25 guests