cefsharp.core.runtime error in Winforms NUnit .NET framework

58 Views Asked by At

Error - System.IO.FileLoadException: 'Could not load file or assembly 'CefSharp.Core.Runtime, Version=121.3.130.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

Code

using System;
using NUnit.Framework;
using CefSharp;
using System.Threading;
using CefSharp.OffScreen;
using CefSharp.Core;

namespace xxx.Controls.ChromiumTest
{
    [TestFixture]
    [Category("Fast")]
    [Category("Unit")]
    public class ChromiumTest
    {
        [Test] //Enable this as part of RSP-9117
        public void TestChromiumDemo()
        {
            ChromiumRunner runner = new ChromiumRunner();
            runner.RunChromiumDemo();
        }

    }

    public class ChromiumRunner
    {
        private ChromiumWebBrowser browser = null;

        public void RunChromiumDemo()
        {
            var settings = new CefSettings()
            {
                MultiThreadedMessageLoop = true
            };

            //Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

            // Create the offscreen Chromium browser.
            browser = new ChromiumWebBrowser("");
            browser.BrowserInitialized += BrowserInitialized;

            while (!browser.IsBrowserInitialized)
            {
                Thread.Sleep(100);
            }

            Cef.Shutdown();
        }

        private void BrowserInitialized(object sender, EventArgs e)
        {
            Assert.IsTrue(browser.IsBrowserInitialized);
            browser.BrowserInitialized -= BrowserInitialized;
        }

    }
}

It throws the error at CefSettings. Below is the short snippet .csproj related to the above test file.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup>
    <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>
    <CefSharpBuildAction>Content</CefSharpBuildAction>
  </PropertyGroup>
  <ItemGroup>
      <PackageReference Include="CefSharp.Common">
        <Version>121.3.130</Version>
      </PackageReference>
      <PackageReference Include="CefSharp.OffScreen">
        <Version>121.3.130</Version>
      </PackageReference>
      <PackageReference Include="CefSharp.WinForms">
        <Version>121.3.130</Version>
      </PackageReference>
  </ItemGroup>
</Project>  
  

Verified that I have Microsoft Visual C++ 2015 - 2019 Redistributable (X64) and (X86) up-to-date.

enter image description here

I did refer these links CefSharp - Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies and confirmed that I have up-to-date Microsoft Visual C++ 2015 - 2019 Redistributable (X64) and (X86). I am not sure what else I am missing. Any help is appreciated. Thank you.

0

There are 0 best solutions below