cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.87k stars 2.92k forks source link

CefSharp in .NET Web Application doesn't work #1127

Closed superlit closed 9 years ago

superlit commented 9 years ago

I'm trying to use CefSharp.OffScreen in a x64 Web application but it doesn't work.

This is the error: "Could not load file or assembly 'CefSharp.BrowserSubprocess.Core.DLL' or one of its dependencies. The specified module could not be found."

I've tried with a console application and it works. The same dll/dat/pack copied in to the bin directory of web application cause a crash.

Can CefSharp be used in web applications? thanks

avspeed commented 9 years ago

Take a look at the user that your web application is running as, CefSharp is trying to launch a process you need to make sure that the user that your web app is running as is authorized to do so. The standard application pool identity will NOT let you launch a process.

superlit commented 9 years ago

Thanks for your reply. The user is running with all privileges. The error happens when the web application is trying to load the assemblies even if I have no code that uses CefSharp objects!

jornh commented 9 years ago

I'm not really familiar with IIS and its .NET web app runtime environment, so take this with a grain of salt but I'm suspecting it has to do with unmanaged code.

Googled for ".net web application unmanaged" and got http://stackoverflow.com/questions/344608/unmanaged-dlls-fail-to-load-on-asp-net-server

The answers in there has a few possible problem pointers and suggestions to try out.

amaitland commented 9 years ago

http://stackoverflow.com/a/17354899/4583726

Galen02 commented 9 years ago

I'm getting the exact same error trying to use CefSharp.Offscreen in a WCF Service. I tried the suggestions mentioned in jornh's post but nothing worked. Has anyone found any resolution to this? I've tried placing the DLLs in the system32 path, the inetsrv path, and other places.
The problem must be that:

  1. The host, IIS Express, is looking in a different location for the DLLS or...
  2. There is another depedency of 'CefSharp.BrowserSubprocess.Core.DLL' that I'm not aware of.

Any help would be greatly appreciated.

amaitland commented 9 years ago

The host, IIS Express, is looking in a different location for the DLLS or...

What happens if you change to hosting using IIS? (Should be easy enough to create a Virtual Directory)

superlit commented 9 years ago

I've tried to put libcat.dll in the System32 directory and now the HTTP 500 error disappears ("Could not load file or assembly 'CefSharp.BrowserSubprocess.Core.DLL' or one of its dependencies. The specified module could not be found."). I've tried to modify the System variable "Path" adding a custom directory containing libcat.dll and It works too. But now I get another unmanaged error in libcat.dll when I initialize the browser component. It seems there is no way to use carSharp in IIS process :-(

thanks to everyone for the suggestions!

amaitland commented 9 years ago

But now I get another unmanaged error in libcat.dll when I initialize the browser component.

At a guess, I'd say it's a threading issue. It's probably worth trying to spawn a single Thread and perform all the CefSharp related tasks (including Initialize/Shutdown). I don't imagine it likes being run on the ThreadPool

amaitland commented 9 years ago

@superlit Also can you confirm how your hosting your application? IIS, IIS Express?

superlit commented 9 years ago

I'm using IIS 8.5. I tried to create a Single-Threaded Apartments and perform all CefSharp related tasks but It doesn't work.

amaitland commented 9 years ago

I tried to create a Single-Threaded Apartments and perform all CefSharp related tasks but It doesn't work.

What does your code look like?

superlit commented 9 years ago
protected HtmlImageDto GetBitmap()
{
    Thread thread = new Thread(new ThreadStart(GetBitmapWorker));
    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
    thread.Join();
    //...
}

private void GetBitmapWorker()
{
    Cef.Initialize(new CefSettings());
    ChromiumWebBrowser bro = new ChromiumWebBrowser(""); //<-- this throw an exception!
    bro.LoadHtml("<html><body>Hello World!</body></html>", "http://www.mysite.com");

    Task<Bitmap> task = bro.ScreenshotAsync();
    //... wait for screenshot
    Bitmap bmp = task.Result;
    //...
}
amaitland commented 9 years ago

Cef being multithreaded by nature, I'm guessing it's not going to like running in STA.

amaitland commented 9 years ago

Scrap that, adding [STAThread] to the OffScreen example seems to work ok.

twilly86 commented 9 years ago

What would be the best way to call CefSharp.Offline from within an IIS hosted web application?

I'm running my web app through an Azure Cloud Service. I'd like to be able to return an image of a screen shot of a specific webpage from my web app. I'm currently using phantomJS but I've found that I can get a 30x performance improvement by using CefSharp so I think it's worth trying to get this to work.

I can run CefSharp.Offline from a backend process outside of IIS, but how would I make calls into that process from my web app? Would NamedPipeServerStream work to communicate between the web app and the console app? I've also seen signalR recommended.

I'm also still stuck on the first error and can't figure out where libcat.dll is coming from that @amaitland used.

Thanks for your help!

jankurianski commented 9 years ago

I'm also still stuck on the first error and can't figure out where libcat.dll is coming from that @amaitland used.

I think this is a spelling mistake and they meant libcef.dll.

cybergogic commented 8 years ago

Hi! I'm copy files to system32 and it's starts good. i tried to create instance Cef.Initialize(new CefSettings()) in separate thread:

Thread tr1 = new Thread(new ThreadStart(CefInit));
            tr1.Start();

        [STAThread]
        void CefInit()
        {
            Cef.Initialize(new CefSettings());
            //ChromiumWebBrowser web01 = new ChromiumWebBrowser("http://www.instagram.com/explore/tags/day"); //<-- this throw an exception!
            //web01.LoadingStateChanged += Web01_LoadingStateChanged;
            Cef.Shutdown();           
        }

and has got:

"iisexpress.exe" (CLR v4.0.30319: DefaultDomain)."C:\Users\Gogic\AppData\Local\Temp\Temporary ASP.NET Files\vs\a17045ba\eec5010\assembly\dl3\5bd97149\9f0a43f4_9286d101\CefSharp.Core.DLL". Can't find or open PDB file. Программа "[9832] iisexpress.exe" closed with code -2147483645 (0x80000003).

Any suggestions?

amaitland commented 8 years ago

I've never been able to get it working under IIS and nobody has reported back saying they have, so it may not be possible. Use the links above for background info, if you can get it working by all means report back.

Regarding #1646 be patient, you asked your question once, that is enough.

Robar666 commented 8 years ago

@cybergogic: I've a simliar issue. I'm trying to initialize CefSharp during a Azure Worker Role start up and end up with the error: The program '[12628] WaWorkerHost.exe' has exited with code -2147483645 (0x80000003).

Steps to reproduce:

Robar666 commented 8 years ago

For future users which might stumble across this issue.

I've found a solution which may work for my use case. I'm using CefGlue and it seems to work with the Azure Worker Role.

I've created a repo with my findings and a small example. https://github.com/Robar666/CefGlueScreenshot

twilly86 commented 8 years ago

Thanks for sharing, how is the performance? Have you tried using PhantomJS?

On Tue, May 31, 2016 at 9:13 AM, Robar666 notifications@github.com wrote:

For future users which might stumble across this issue.

I've found a solution which may work for my use case. I'm using CefGlue and it seems to work with the Azure Worker Role.

I've created a repo with my findings and a small example. https://github.com/Robar666/CefGlueScreenshot

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cefsharp/CefSharp/issues/1127#issuecomment-222720331, or mute the thread https://github.com/notifications/unsubscribe/ADVbhoYqAqO79_IBkcCA4d_JtfvuxA3Rks5qHFAcgaJpZM4Fagdq .

Robar666 commented 8 years ago

@twilly86 It works for me, but I have not done any performance testing.

Nope I have tested PhantomJS, since it was no option for me.

twilly86 commented 8 years ago

Getting the following error when I download the zip and try and build..

[image: Inline image 1]

Error 2 NuGet Package restore failed for project CefGlueScreenshot: Unable to find version '51.1.1' of package 'ChromiumEmbedded.Redistributable-win-x64'.. 0 0

This is the package right?

https://www.nuget.org/packages/cef.redist.x86/3.2526.1362

On Tue, May 31, 2016 at 9:27 AM, Robar666 notifications@github.com wrote:

@twilly86 https://github.com/twilly86 It works for me, but I have not done any performance testing.

Nope I have tested PhantomJS, since it was no option for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cefsharp/CefSharp/issues/1127#issuecomment-222724738, or mute the thread https://github.com/notifications/unsubscribe/ADVbhh8rgvkY3tiCQsNa3noQ7PVx2Un_ks5qHFNbgaJpZM4Fagdq .

amaitland commented 8 years ago

@twilly86 @Robar666 As this discussion is no longer CefSharp related, please discuss in the CefGlueScreenShot repository.

Rathna-K commented 5 years ago

if I am reading this whole thread correctly, there are several people asking the same thing but after several tried there is no working solution as of now for making Cef Offscreen work with IIS Web App. am I right?

ramon-mendes commented 4 years ago

Just for the record, I had this same issue when running my .Net MVC. Solved it by changing this setting: image ...x64 in my case, as my MVC is x64