How do you use CefSharp in a WCF Service?
Asked Answered
D

2

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.
Duello answered 15/7, 2015 at 20:37 Comment(9)
Cef.Initialize() has a performDependencyCheck param. Does it return an error?Malek
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.Duello
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.Malek
Looks like Asp.Net doesn't handle unmanaged assembles particularly well. I believe the problem your facing is outlined at #17333395Malek
There is a similar question on github, prob best to join the conversation there github.com/cefsharp/CefSharp/issues/1127#issuecomment-122331752Malek
I tried the solutions that the link leads to without any luck. Does WCF look for Dlls in a different location than ASP .NET?Duello
If you post on GitHub you can see if the other user had any success.Malek
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.Disrelish
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.Duello
C
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.

Camara answered 27/7, 2015 at 7:25 Comment(4)
Does CefSharp.Offscreen still require access to the desktop? I thought that it didn't create any windows. Correct me if I'm wrong.Duello
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.Duello
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.Camara
@AkashKava have you found any information regarding the CefSharp.Offscreen project. Isn't there a solution to use CefSharp in an web hosted environment?Quagga
C
0

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

Celiaceliac answered 20/1, 2016 at 0:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.