Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run CefSharp.OffScreen from tests #2900

Closed
rabejens opened this issue Sep 11, 2019 · 9 comments
Closed

Unable to run CefSharp.OffScreen from tests #2900

rabejens opened this issue Sep 11, 2019 · 9 comments

Comments

@rabejens
Copy link

  • What version of the product are you using?

75.1.142.0

  • What architecture x86 or x64?

Both

  • On what operating system?

Windows 10 x64

  • Are you using WinForms, WPF or OffScreen?

OffScreen

  • What steps will reproduce the problem?
  1. Create a library targeting .net Framework 4.7.2
  2. Set it to compile for x86 or x64
  3. Add CefSharp.OffScreen
  4. Add this small class:
using System;
using System.IO;
using CefSharp;
using CefSharp.OffScreen;

namespace Crash {

    public static class ReproduceCrash {

        public static void Reproduce() {
            CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
            var settings = new CefSettings {
                BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "CefSharp.BrowserSubprocess.exe")
            };
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
        }
    }
}
  1. Create a Console Application for .net 4.7.2
  2. Add the XUnit dependencies:
coverlet.collector
Microsoft.NET.Test.Sdk
xunit
xunit.runner.visualstudio
  1. Create a class which contains this unit test:
[Fact]
public void Crashes() {
    ReproduceCrash.Reproduce();
}
  1. Add ReproduceCrash.Reproduce(); to Program.cs
  2. Set a breakpoint on the ReproduceCrash.Reproduce() method
  3. Run the test in Debug mode
  4. Run the main program Program.cs
  • What is the expected output? What do you see instead?

When running the test, I expect that I can single-step through the method without any problems, but when it comes to the line

Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

I get this:

System.ArgumentException: 'Cannot pass a GCHandle across AppDomains.
Parameter name: handle'

When running the Program.cs directly, it works.

@amaitland
Copy link
Member

Duplicate #351

This is a limitation of Visual C++

@jankurianski
Copy link
Member

Nunit's console runner works using --domain=None --inprocess. See my comment here: #700 (comment)

@rabejens
Copy link
Author

The funny thing is, when I use the NETCore3 version, it works from xUnit tests. Unfortunately I can't use it in my case, because the website I need to remote control includes a file upload which I have to automate using UIAutomation.

@amaitland
Copy link
Member

.Net Core doesn't support creating additional AppDomains as per https://docs.microsoft.com/en-us/dotnet/core/porting/net-framework-tech-unavailable#appdomains

Any test framework that supports .Net Core should be usable with CefSharp when run from .Net Core.

@captainjono
Copy link

I have patched Nunit v2 to run unit tests in a single app-domain to make it compatible with CEF & Test Explorer. No console runner required, make sure CEF .dlls copy to output dir.

Feel free to use it or use its code to patch an existing runner. No warrenty.
Janison.Nunit.TestAdapter.zip

@captainjono
Copy link

captainjono commented Mar 20, 2020

Good to know! This info should be part of an intro guide to help others. No integrated testing was a deal-breaker for me - ive been running the patched runner for a few years and decided to post it up to make the story better.

@amaitland
Copy link
Member

Feel free to use it or use its code to patch an existing runner. No warrenty.
Janison.Nunit.TestAdapter.zip

A link to your GitHub fork would be better, you can upload a binary to the releases section. Just a link to a binary saying no warranty isn't very reassuring, it's not something I'd consider download. How am I supposed to fix any bugs with only a zip file?

It's something others might also be interested in contributing to, maintaining an active fork and keeping up to date.

This info should be part of an intro guide to help others

Anyone with a GitHub account can edit the Wiki. I am actively trying to improve the documentation, contributions from users like yourself are required to cover the vast array of topics involved.

@captainjono
Copy link

captainjono commented Mar 20, 2020

I turned a dead-end into an option for someone. Now with your contribution, thats 2 options.

Sounds like I have done my part to further the community. This is how communities used to work before enterprises monitised them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants