20

I am trying to use the CefSharp.OffScreen(41.0.0) Nuget Package within a WCF Service Application, and I'm getting the following error while trying to run the service from Visual Studio 2013:

Could not load file or assembly 'CefSharp.BrowserSubprocess.Core.DLL' or one of its dependencies. The specified module could not be found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp.BrowserSubprocess.Core.DLL' or one of its dependencies. The specified module could not be found.

The mentioned assembly is present in the project's bin folder as well as all the required assemblies listed on CefSharp's Website. If there is in fact another assembly required I haven't figured out what it is.

A few other points worth mentioning:

  • It is easy to reproduce: Start with VS2013's "WCF Service Application" template simply added the CefSharp.Offscreen Nuget Package.
  • I build the project in x86.
  • CefSharp also depends on the Visual Studio C++ 2012 redistributables. I copied those file into the bin folder but still get the same error.
  • I tried the solutions in the SO question here, to no avail.
  • CefSharp works fine when referenced from a Console Application or WPF Application.
Community
  • 1
  • 1
Galen
  • 499
  • 5
  • 14
  • Cef.Initialize() has a performDependencyCheck param. Does it return an error? – amaitland Jul 15 '15 at 22:07
  • No code has been add to the project yet (other than what comes with the WCF Service Application template). I've only added the CefSharp references thru the CefSharp.Offscreen nuget package. – Galen Jul 16 '15 at 14:24
  • If you compare the project references are they the same as your console app? There should only be `CefSharp`, `CefSharp.Core` and `CefSharp.OffScreen`? There should be no reference to the `BrowserSubProcess`, it's spawned when your application runs, it's not a dependency. – amaitland Jul 16 '15 at 22:49
  • Looks like `Asp.Net` doesn't handle `unmanaged` assembles particularly well. I believe the problem your facing is outlined at http://stackoverflow.com/questions/17332895/embedded-unmanaged-dlls-dont-load-in-asp-net – amaitland Jul 17 '15 at 01:40
  • There is a similar question on github, prob best to join the conversation there https://github.com/cefsharp/CefSharp/issues/1127#issuecomment-122331752 – amaitland Jul 18 '15 at 12:11
  • I tried the solutions that the link leads to without any luck. Does WCF look for Dlls in a different location than ASP .NET? – Galen Jul 20 '15 at 20:16
  • If you post on `GitHub` you can see if the other user had any success. – amaitland Jul 20 '15 at 22:49
  • Are you running it in IIS or a self hosted service? If in IIS, look at the app pool that the app is running it, it could be that you need to enable 32bit applications if you are building for x86 in the advanced settings. I came into something similar. Or try to run in x64 but make sure all the projects are set to build to the same thing. – Kevin Green Jul 23 '15 at 18:59
  • I'm running it in IIS. I set "Enable 32bit applications" in all the app pools and it gets the service running but then it throws a file not found exception after Cef.Initialize is called. System.IO.FileNotFoundException was unhandled Message: Could not load file or assembly 'CefSharp, Version=41.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The system cannot find the file specified. – Galen Jul 23 '15 at 20:24

2 Answers2

4

Few points,

IIS cannot access Desktop

So you can't run anything that needs a desktop. Your Console and WPF application has access to Desktop and are called user interactive processes.

CEF needs desktop

Cef will need Window manager to create window, without which it cannot render page. This is the reason, the error is misleading here, as IIS cannot load dependent assemblies which require Desktop interaction unless Allow service to interact with Desktop is selected for IIS process in Windows Services.

Console application is only option with Login

You will have to run your application as console and you will need to login to desktop, allowing IIS to interact with desktop is not a good option and I don't even know what kind of problems it might have.

You can set your server to auto login to some user by modifying registry and set your console application in your startup. So this way everytime server will be restarted, your server will automatically login to specified user and your console app will start. (Windows 8.1 has little difficulty but you will get some solution).

Custom Windows Service with Desktop Access

You can change your application type to Windows Service instead of Console and you can install your windows service that allows access to desktop shown in this article, beware, there are problems that this will work only if somebody is logged on to server.

http://www.codeproject.com/Articles/4891/Interact-With-Desktop-when-Installing-Windows-Serv

PhantomJS headless browser

There is PhantomJS headless browser which you can run in IIS/Windows Service without need to interact with desktop, however you will need to shift your code to JavaScript instead of C#. There are other libraries to manage PhantomJS from your app as well.

Akash Kava
  • 39,066
  • 20
  • 121
  • 167
  • Does CefSharp.Offscreen still require access to the desktop? I thought that it didn't create any windows. Correct me if I'm wrong. – Galen Jul 27 '15 at 14:22
  • Is the IIS service that you are referring to called, "Windows Process Activation Service". I don't see any services that contain IIS in their name. – Galen Jul 27 '15 at 14:34
  • It is world wide web service I think, and even if it says CefSharp.Offscreen, it just does not display window, but it does need desktop I think because Windows will not load relevant GUI libraries needed. I am not sure but I will take a look later. – Akash Kava Jul 27 '15 at 18:18
  • @AkashKava have you found any information regarding the CefSharp.Offscreen project. Isn't there a solution to use CefSharp in an web hosted environment? – Robar May 24 '16 at 14:37
0

According to this link it appears that the solution to this problem is to run the CefSharp code in a [STAThread] thread.

Telavian
  • 3,752
  • 6
  • 36
  • 60