BadImageFormatException with CefSharp nuget
I'm trying to have a play with CefSharp but getting the BadImageFormatException when I run the script.
Whilst I suspect it has something to do with x86/64 assemblies, I cannot seem to resolve it and need some help.
My linqpad script is basic as, and following the CefSharp Minimal example
I'm not doing any initialisation, and the below call throws the exception.
_var browser = new ChromiumWebBrowser(testUrl); _
I'm loading the Offscreen.NETCore package
I've tried the following -
1. Linqpad 6 x64 - throws exception
2. Linqpad 6 x84 - throws exception
3. Linqpad 5 x86 (using the .NETFramework package) - FileNotFoundException -> CefSharp.Core
4. VS 2019 console app - AnyCPU or x64 targets - Both work
I even tried locating the x64 CefSharp dll's and copying them into the respective query directories, but no manner of hacking has produced....
Is this is x86/64 thing ? Or is it another issue manifesting itself as a BadImageFormatException ?
ideas ?
.linq file attached.
Comments
That NuGet package has been designed not to work with tools such as LINQPad. It relies on the full Visual Studio / msbuild ecosystem and has its own custom mechanism for resolving unmanaged DLLs instead of using convention-based defaults defined by NuGet.
Have you using the Microsoft.Web.WebView2 package? It provides the same functionality, i.e., a Chromium engine, and runs fine within LINQPad. The WebView2 runtime is also now a standard part of Windows 10.
Thanks Joe, Had not seen the WebView2, will go an check it out. Don't have a dependency on CefSharp.
Do you have any docs on how linqpad resolves/finds and consumes dll's from nuget packages in relation to the working directory/execution context of the current query ?
I did have a stab at manually moving dll's around to trick the query into running, but my knowledge of what goes on under the hood is limited.
Not important, just interested....
The working directory is not really relevant. When resolving references from NuGet packages, LINQPad looks for managed and native DLLs in the folders defined by the NuGet specification. In the case of native DLLs, these should be located in the runtimes folder, within sub-folders named {platform}-{architecture}\native:
https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks#architecture-specific-folders
Ta, I'll have a read.