0

I get the exception CefSharp: Could not load file or assembly CefSharp.Core.Runtime. I found similar questions with CefSharp.Core.dll or CefSharp.Core.Runtime.dll, but in my case it is with CefSharp.Core.Runtime, without dll.

I installed CefSharp.OffScreen 96.0.180.0 using nuget.

I installed the latest supported Microsoft Visual C++ Redistributable packages for Visual Studio 2022. I have all the required files. I followed these steps (although the error in my case is with the Core.Runtime).

My code:

string url = "MY_URL";
using (var browser = new ChromiumWebBrowser(url))
   {
      var initialLoadResponse = await browser.WaitForInitialLoadAsync(); <- ERROR!!!
      var html = await browser.GetBrowser().MainFrame.GetSourceAsync();
      HERE_I_DO_SOME_STUFF_WITH_MY_HTML;
   }

It breaks when I try to get the initial load response.

I also get the messages

Exception thrown: 'System.IO.FileNotFoundException' in CefSharp.OffScreen.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll

in the console.

My app is .net462.

I looked at several questions in SO and none of them worked. The only one I didn't try is the x64 vs x86 solution because I don't understand the consequences (if I change it, will it affect to the other developers? will it compile in the Azure server?). The only thing I did here is adding the following lines in the csproj file: enter image description here

I have these files in bin/Debug:

Debug folder

I have these files in bin/Debug/x64:

x64 folder

The folder bin/Debug/x86 looks exactly the same as bin/Debug/x64.

I had previously installed CefSharp in a POC in the same solution, in a project in .net6 and it worked without any issue.

Any ideas?

xavier
  • 1,860
  • 4
  • 18
  • 46
  • Which AnyCpu solution did you choose? https://github.com/cefsharp/CefSharp/issues/1714 – amaitland Dec 22 '21 at 19:31
  • Where? I debug it with the "Any CPU". Sorry, I don't understand the question... :-( – xavier Dec 22 '21 at 19:49
  • Are you targeting AnyCpu? If yes then you need to tell .Net how to load the arch specific assemblies. See https://github.com/cefsharp/CefSharp/issues/1714 – amaitland Dec 22 '21 at 19:54
  • I already saw this page. There are 3 problems with it: 1) As I mention in the question, I am afraid to specify a specific target, because I don't know if this will affect the other people and/or the Azure server. 2) The Prefer 32-bits option appears disabled (I use VS 2022) and 3) I tried to select either target (x86 and x64) and in both cases I the application crashed before. Since I don't know what I do and I have the aforementioned concerns, I didn't go on trying this possibility. I'll give one more try, though... – xavier Dec 22 '21 at 20:04
  • Add a call to CefRuntime.SubscribeAnyCpuAssemblyResolver() very early in your application. I'd suggest in Program.Main You don't need to change to platform or PlatformTarget. – amaitland Dec 22 '21 at 20:17
  • I use `OwinStartup` and there is no main. I added it in `ConfigureApplication` and I still have the same problem... :-( – xavier Dec 23 '21 at 11:25
  • In that case I'd suggest using https://github.com/hardkoded/puppeteer-sharp/ instead. – amaitland Dec 23 '21 at 19:27
  • The suggestion is based on the fact I use `Owin` or because I couldn't fix the problem? Just to know... Thank you a lot for your help. – xavier Dec 24 '21 at 10:33
  • 1
    Puppateer is better suited to be run from within asp Net. – amaitland Dec 24 '21 at 22:39

0 Answers0