简体   繁体   中英

FileNotFoundException for CefSharp when running XUnit test

I am making some test with XUnit on a application using CefSarp.

But the test are crashing with the exception :

System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp, Version=55.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138'or one of its dependencies. The system cannot find the file specified.

at CefSharp.CefSharpApp.OnBeforeChildProcessLaunch(CefSharpApp* , CefRefPtr* commandLine)

On Xunit issue tracker ( https://github.com/xunit/xunit/issues/4 ) the workaround is to set the shadowCopy option to false. But this does not work for me.

CefSharp have some files which need to be next the executable ( https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#Runtime_dependencies ). All those files are present in the bin folder and when I check the current directory with System.IO.Directory.GetCurrentDirectory() , this is the right folder.

I tried to use the SetDllDirectory from Kernel32 to add the bin folder but it change nothing.

I also tried to load the assembly manualy with Assembly.LoadFile() . This call succeed but later when cef is initialized, the exception still happen. So the problem is probably not finding the assembly itself but the files needed by CefSharp.

Where should I put all the CefSharp file to allow XUnit to find them? I have the same problem with the Xunit test integrated in VisualStudio and with the Xunit console.

Edit :

Problem solved (see anwser). All the test are passing except test created with SpecFlow .

It throw the Could not load file or assembly but with CefSharp.Core this time.

The problem was that CefSharp does not support multiple AppDomains. The config file of the unit test in the CefSharp repo contains the following :

<configuration>
  <appSettings>
    <add key="xunit.appDomain" value="denied"/>
  </appSettings>
</configuration>

which prevent XUnit to use multiple AppDomains. This config must be added in the app.config of each test library .

The CefSharp test also contains

var isDefault = AppDomain.CurrentDomain.IsDefaultAppDomain();
if (!isDefault)
{
     throw new Exception(@"Add <add key=""xunit.appDomain"" value=""denied""/> to your app.config to disable appdomains");
}

to check is multiple AppDomains are used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM