Home > Software design >  Unknown build error, 'Could not find assembly 'CefSharp, Version=107.1.90.0 ...''
Unknown build error, 'Could not find assembly 'CefSharp, Version=107.1.90.0 ...''

Time:11-23

After installing the following NuGet packages:

  • cef.redist.x64
  • CefSharp.Common
  • CefSharp.Wpf

And following the following video tutorial: How to make a Cefsharp Web Browser in WPF C#, adding an app manifest file and uncommenting the Windows 10 key.

Then, referencing the CefSharp component in the Xaml window header: xmlns:cef="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf".

Following these steps, the tag <cef:ChromiumWebBrowser Address="https://google.ca" Height="400" Width="400"/> should construct the browser element. Instead, the following error appears, signaling that Xaml line:

Unknown build error, 'Could not find assembly 'CefSharp, Version=107.1.90.0 ...' Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.

Visual Studio suggests adding a reference to the CefSharp library, but clicking on this suggestion always fails for whatever reason.

By consulting the documentation, one can find a minimal running example. Yet, the quickstart example didn't even work for me (build errors and such).

By consulting answers on StackOverflow, it would appear that the correct Visual C Redistributable installation is required, and that not having this installed could cause referencing issues. This did not solve the problem for me.

I also tried changing build values, build configurations, uncommenting certain lines in the configuration file, and consulted documentation and other questions on StackOverflow. None of them mentioned having the exact error.

CodePudding user response:

According to your tags you are using .Net 6.0 for which you need to use the CefSharp.Wpf.netcore package. The CefSharp.Wpf package is for .Net 4.x

For .Net 6.0 you need to follow the instructions at https://github.com/cefsharp/CefSharp/wiki/Quick-Start-For-MS-.Net-5.0-or-greater

Manually referencing the dlls isn't recommend or required.

CodePudding user response:

The problem is related to referencing the correct dlls. For whatever reason, they don't get project referenced by performing the NuGet package installations.

NuGet packages get installed to a common local folder under C:\Users\username\.nuget. So adding references to the NuGet packages manually worked for me.

Add > Project Reference... > Browse.. and add the following dlls:

  • ....nuget\packages\cefsharp.wpf\107.1.90\lib\net462\CefSharp.Wpf.dll
  • ....nuget\packages\cefsharp.common\107.1.90\lib\net452\CefSharp.Core.dll
  • ....nuget\packages\cefsharp.common\107.1.90\lib\net452\CefSharp.dll

(Folders may not be numbered in the exact same way, but these are the references to CefSharp.Wpf.dll, CefSharp.Core.dll, CefSharp.dll.)

  • Related