Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 10 2016 09:45
    User @amaitland unbanned @aolko
  • Oct 10 2016 09:36
    @amaitland banned @aolko
  • Feb 11 2016 05:56
    User @amaitland unbanned @miyakedev from this room
  • Feb 10 2016 19:59
    @amaitland banned @miyakedev
hicks86
@hicks86
Thanks will try that @mitchcapper
hicks86
@hicks86

Hey, just installed Cefsharp for a WinForms project (.net 4.6.2) on an Add-In express taskpane (this allows the app to appear in Microsoft Excel). Currently when trying to run the program I am unable to get past a System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'CefSharp, Version=94.4.50.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The system cannot find the file specified. when trying to run the application. I have gone through the Readme.txt ensuring all of the .dll are included in the bin folders etc. I have done a clean where I removed both bin and obj folders.

What I have noticed thought in the bin folder there is a x86, x64 folders both have all of the correct .DLL and there are also some DLL in the root Debug folder that contains the x86/x64 folder but not all of them (I initially was looking in here to check the .DLL that you recommend checking for in the Readme).

bin
 - Debug
   - x64
   - x86

Edit: so to be clear the Add-In express taskpane is WinForms, and on top of this I have created a WinForms UserControl in which the ChromiumBrowser sits on top of.

OK so I fired up Process Monitor and can see Word (WINWORD.exe) and in it I can see CefSharp.Core.dll, CefSharp.dll and CefSharp.Winforms.dll under the root bin\Debugfolder. I switched on all of the exceptions in VS2019 and there's now a slightly different message now but I believe its all related:

'The assembly with display name 'CefSharp.Core.Runtime' failed to load in the 'Load' binding context of the AppDomain with ID 3. The cause of the failure was: System.BadImageFormatException: Could not load file or assembly 'CefSharp.Core.Runtime, Version=94.4.50.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. An attempt was made to load a program with an incorrect format.'

I have noticed though in the x64/x86 folders there are a lot more DLL's and the CefSharp.BrowserSubprocess.exe etc. - however as I mentioned WINWORD is not looking in those folders. Thoughts?

Edit: apologies I meant Word and NOT Excel in original question - although it will probably have same issue.

Alex Maitland
@amaitland

I managed to write a test that sometimes fails

@jsoldi Interesting, thanks. Please create a new issue https://github.com/cefsharp/CefSharp/issues/new/choose

For OffScreen it might be simpler to defer to the user to call Cef.Initialze

I couldn't find a way to shutdown CEF inside the test since even if I use ConfigureAwait(true), the last line always runs on a different thread.

There's no sync context so continuations run on the thread pool by default. The test fixture handles this using AsyncContextThread

I did succeed to go a bit further. I can display the text in the browser but as text (not rendered).

@larouchefrancois Most often this is the caused by the mimeType (content type) being incorrect, that's the first thing to check.

I saw the comment at the bottom of the example that says
"The IWebBrowser.RegisterResourceHandler and IWebBrowser.UnRegisterResourceHandler extension methods provide a simple means of providing an IResourceHandler for a given Url."
Problem is where do you use them? I tried to use in many places to no avail.

Those methods are for registering static resources, things that don't change. If you are trying to proxy every request then they aren't for you.

Here's the code of my CustomResponseHandler (I tried few things):

Looks ok on the surface, without running it I cannot really say for sure.

does dlls have to be inside same folder?

@pwilkowski That's how they are resolved by default, if you wish to move them into a different folder then you need to add additional code.

What version are you using? Are you using NetCore 3.1/.Net 5.0?

Unfortunately BadImageFormatException when loading a VC++ dll under .Net Core 3.1/Net 5.0 is rather misleading. It can in fact mean a number of things. Any attempt to load CefSharp.Core.Runtime.dll which fails for any reason results in BadImageFormatException. If CefSharp.Core.Runtime.dll is unable to load libcef.dll you will also get the same BadImageFormatException.

larouchefrancois
@larouchefrancois
@amaitland ok that was a weird case... with your content type comment I did a quick check. I already looked at first but checked again. The content type was with "text/html; charset=UTF-8" The charset=UTF-8 was enough to confuse the browser and render it as text. I manually changed it in debug mode to "text/html" and it worked! I don't know if it is considered as a bug but that means I'll have to remove or handle anything after text/html if it happens. I'll check the rest of the code to see the behavior is ok but I think it's alright. Thanks :)
Alex Maitland
@amaitland

I don't know if it is considered as a bug but that means I'll have to remove or handle anything after text/html if it happens

@larouchefrancois The CefResponse object expects that MimeType and CharSet are set separately.

https://github.com/chromiumembedded/cef/blob/a4d71d8fe2d7422c8e48128f55a503753e2d01c8/include/cef_response.h#L124

https://github.com/cefsharp/CefSharp/blob/cefsharp/94/CefSharp/ResourceHandler.cs#L37

Alex Maitland
@amaitland

I'm using the HwndForm wrapping in CefSharp and want to use full screen via F9, and cancel it via ESC. I'm trying to implement IKeyboardHandler but I have to say I have no idea what I'm supposed to do. The only example available is for WinForms and there are not many matches in the APIs there.

@NickeNor What does your code look like so far? Basically it should be pretty simple, check for the windows key code, execute some javascript to exit fullscreen. If you have a WinForms example that should may very easily.

https://developer.mozilla.org/en-US/docs/Web/API/Document/exitFullscreen

Also implemented IDisplayHandler, looks slightly less intimidating but still hard to do

You can inherit from https://cefsharp.github.io/api/94.4.x/html/T_CefSharp_Handler_DisplayHandler.htm and override just the methods you need rather than implementing the whole IDisplayHandler interface.

2 replies

The assembly with display name 'CefSharp.Core.Runtime' failed to load in the 'Load' binding context of the AppDomain with ID 3

@hicks86 First step is to confirm if your plugin is going to be run in the default AppDomain. Because CefSharp is built with Visual C++ which only runs in the default AppDomain (won't work from a different one).

If you are then it should just be a matter of loading the libraries.

If not then you can use

  • Try using NetOffice which I believe others have successfully integrated CefSharp into office applications with, not tried myself so you'd probayl need to confirm with the NetOffice devs first.
  • another CEF based wrapper like CefGlue or look for a different browser altogether
pwilkowski
@pwilkowski
@amaitland @shawty sorry for late reply, I have been banging my head against the wall with this. So more context: I am making a plugin for some existing application. So my output is DLL. Now the problem is that my DLL is already being dynamically loaded in runtime via custom loader. This apparently has some issues with loading mixed assemblies. So I am exploring my options here how could I embbedd CefSharp into it. There is no problem with x64/x86 at all. Only x64 is supported. So that is 100% not a problem with target, any references or settings to 32 bits have been removed or explicitly disabled. My code compiles just fine, but as soon as code reaches CefSettings it dies with BadImageFormatException. I am able to load Assembly of Offscreen.dll and even see the Types inside, howerver as soon as i try to instantiate CefSettings, it dies (on CefSharp.Core.Runtime)
On a side node, I have tried to compile some test program into single executable and it runs just fine, bit shame dotnet doesn't support a single dll as well as it would solve the issues.
Alex Maitland
@amaitland
@pwilkowski What version of .net are you using? Plugins usually require additional code to load dlls at runtime.
Single dll wouldn't help as the unmanaged resources have to be loaded from disk.
Bu─čra
@BgR8
how to run extension on browser using c#
pwilkowski
@pwilkowski
@amaitland net5.0-windows
Alex Maitland
@amaitland
@pwilkowski https://docs.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support has generic instructions for plugin assembly resolution under. Net 5.0/Net core 3.1. Does your host application use an assemblyloadcontext?
Make sure you have specified a RuntimeIdentifier so you have an arch specific build
@BgR8 Extension support is extremely limited. Details are at cefsharp/CefSharp#2497
Alex Maitland
@amaitland
Make sure the extension api you require are supported first
Alex Maitland
@amaitland

@pwilkowski Also did you set <EnableDynamicLoading>true</EnableDynamicLoading> in your csproj file so the dependencies are copied to your plugin output?
https://docs.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support#plugin-with-library-dependencies

They would be copied by default if you did a dotnet publish

pwilkowski
@pwilkowski
@amaitland thanks i used McMaster.NETCore.Plugins wrapped CEF inside DLL, loaded that DLL with this plugins and it worked.
hicks86
@hicks86

The assembly with display name 'CefSharp.Core.Runtime' failed to load in the 'Load' binding context of the AppDomain with ID 3

@hicks86 First step is to confirm if your plugin is going to be run in the default AppDomain. Because CefSharp is built with Visual C++ which only runs in the default AppDomain (won't work from a different one).

If you are then it should just be a matter of loading the libraries.

If not then you can use

  • Try using NetOffice which I believe others have successfully integrated CefSharp into office applications with, not tried myself so you'd probayl need to confirm with the NetOffice devs first.
  • another CEF based wrapper like CefGlue or look for a different browser altogether

Hi I have checked and the addin-express and VSTO taskpanes load into a separate domain. So unfortunately it looks like CefSharp is out - our project is too big and tied into the AddIn for now but I'll note down that library for future. I will also take a look at CefGlue as you recommended. Cheers

larouchefrancois
@larouchefrancois

@amaitland So things are going well on my handling with resourcehandler except once I'm at OnResourceLoadComplete I don't get the WebBrowser object with the newly followed Url info. For instance, on the first load of the page I get about:blank instead of the url requested. Why I'm mentioning that event is because on the normal flow it's where it gets updated. And in my case it's where I'm updating my form to get the new data. For example, I'm only updating the info if the request url = to the one in the browser (that's how I know if it's the main request or any subsequent calls for other resources like css, pictures, js, etc) in the raised event , something in the like of

    private void chromiumBrowser_OnResourceLoadCompleteEvent(object sender, OnResourceLoadCompleteEventArgs args)
    {
                // If main url
                if (args.ChromiumWebBrowser.Address == args.Request.Url)
                {
                    this.InvokeOnUiThreadIfRequired(() =>
                    {
                        // Update UI controls

I tried to register the resourcehandler in ProcessRequestAsync with ChromiumWebBrowser.RegisterResourceHandler(request.Url, stream); but it doesn't make any difference. Obviously I can figure out a workaround but it would be dirty and I would rather prefer to get the clean supported way. I was wondering if I was missing something.

jsoldi
@jsoldi

Interesting, thanks. Please create a new issue https://github.com/cefsharp/CefSharp/issues/new/choose

@amaitland OK I created a bug report cefsharp/CefSharp#3850. Let me know if it needs any additional info.

larouchefrancois
@larouchefrancois
@amaitland To give more info to help. I saw that only on the initial request of the url the ChromiumWebBrowser contains the former loaded page URL. All subsequent requests it for resources contained in the main url (initial request) such as css, images, etc will have the proper Address in the ChromiumWebBrowser. And the Browser and its Frame as well (which I guess is really important as well)
What I wonder is when the ChromiumWebBrowser gets its Address set, and the Browser object set as well. I tried to first search in the CefSharp code and I didn't find it and then in Cef project and not quite find it. Problem with hooking and event type of solution it's really hard to debug or analyze. If I can find perhaps I can do it. Obviously in the normal flow it is set somewhere before OnResourceLoadComplete. I would be very curious when it happens and if I can change it.
pwilkowski
@pwilkowski
It appears to be I cannot call Cef.Initialize second time but there is something strange going on. I have created DLL plugin with cef that is suppose to shutdown properly when unloaded. Loading it second time crashes process. Is there any way to completely uninitialize CEF or at least grab the previous "initialization" ?
pwilkowski
@pwilkowski
do i need to dispose settings also?
pwilkowski
@pwilkowski
alternatively is there a way to "cache" existing cef handles?
larouchefrancois
@larouchefrancois
@amaitland Last observation that could be of interest. I noticed that the initial page I'm calling is not part of the Network requests in the devtool associated to my project. I tried to force the Url on the ChromiumWebBrowser and if it helps for the displaying of my data it does not work in there and it should be taken care of. I'm going to continue to investigating. I was hoping that you would say hey! It's an easy one just check this or set that since you know so much the solution :)
Angshuman Agarwal
@angshuman-agarwal
@amaitland : How do we enable permission api for clipboard access : https://googlechrome.github.io/samples/async-clipboard/. Is there a way please ? I tried in CefSharp (WPF) v92, it does not seem to work due to permission denied.
chacham2
@chacham2
How do you change the font size of the browser? I'm looking to start it as a browser preference, not page by page.
chacham2
@chacham2
So far, i have tried BrowserSettings.DefaultFontSize, BrowserSettings.DefaultFixedFontSize, CefSettings.CefCommandLineArgs.Add("minimum_font_size", "18"), CefSettings.CefCommandLineArgs.Add("minimum_logical_font_size", "18"),
chacham2
@chacham2
Wait a sec, i set BrowserSettings.DefaultFontSize, BrowserSettings.DefaultFixedFontSize but never told cef to use those settings. That is, when using CefSettings, the object must be passed via Cef.Initialize(Settings). Is there something similar for BrowserSettings?
To answer my own question, it's passed when starting the browser: New ChromiumWebBrowser("<url>") Though. it still seems not to b doing anything.
chacham2
@chacham2
Okay, it works if BrowserSettings is used to set MinimumFontSize. I think i will set all 4 just in case. Not sure the difference between them, necesarily.
Krishna Chaitanya M
@chaitanyajun12

@amaitland Is there an API in WinForms CefSharp for passing JSON string from JS to C# layer ?

I see that there is one in WPF CefSharp JavascriptMessageReceived. I see there is no equivalent in Winforms CefSharp. Is there one?

Krishna Chaitanya M
@chaitanyajun12
@chacham2 I see this event is present only in WPF CefSharp library and not in Winforms CefSharp. Is there any alternative for Winforms CefSharp?
chacham2
@chacham2
I'm using it in winforms
Actually I don't see the JavascriptMessageReceived in Winforms library..
chacham2
@chacham2
The link i sent is the ChromiumWebBrowser which is used in WinForms
I mean, i am using that right now in the current project i am working on.
Krishna Chaitanya M
@chaitanyajun12
image.png@chacham2 But the link which you sent is Wpf library only
Please correct me if I'm not understanding correctly.
So, basically in my project I'm using CefSharp.Winforms library only and not CefSharp.Wpf library.
chacham2
@chacham2
Okay, now i see, the link shows wpf. Sorry, i missed that. But, i am using it in WinForms