AutoCAD 2021 CefSharp

AutoCAD 2021 CefSharp

astuy
Contributor Contributor
5,480 Views
13 Replies
Message 1 of 14

AutoCAD 2021 CefSharp

astuy
Contributor
Contributor

Hello,

 

we are using CefSharp (https://www.nuget.org/packages/CefSharp.Wpf/) in one of our AutoCAD-Addins. Until AutoCAD 2020 everything works fine, but since AutoCAD 2021 there is a problem ("Cef::Initialize() failed.").

 

I suspect it's AutoCAD's move from AcWebBrowser to AcCef, which breaks our addin. AcCef uses CEF version 77, but there is no corresponding version of CefSharp, just 75 or 79.

 

What could I do to make it run again? Or could Autodesk switch to a version supported by CefSharp?

 

Thanks, Achim

5,481 Views
13 Replies
Replies (13)
Message 2 of 14

guillaume_aronica
Observer
Observer

Hi,
We have the same problem here, any workaround found?

Thanks

 

 

0 Likes
Message 3 of 14

astuy
Contributor
Contributor

We solved the problem by switching to the WebView-Control. It's Edge-Engine instead of Chromium, but still better than Trident (Internet Explorer) engine of the old Browser Control.

Until now it works. And if it will not work in future, we will search for any other solution.

0 Likes
Message 4 of 14

metzdorf
Explorer
Explorer

Hi,

I have nearly the same problem, but I don't think that the problem is the change from AcWebBrowser to AcCef. I think that the problem are some new UI components like the modal window (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalWindow) or the visual browser of the PaletteSet (Autodesk.AutoCAD.Windows.PaletteSet.AddVisualBrowser).

The biggest problem is to find a different solution to allow a communication between some JS-functions from the website and the remaining parts of AutoCAD.

0 Likes
Message 5 of 14

Anonymous
Not applicable

Hello All,

 

I am facing same issue and getting error {"Cef::Initialize() failed"} with AutoCAD 2021. For all other versions of AUtoCAD it works fine.

Please look into this issue as soon as possible its blocker for our addin.

 

Thanks and regards,

Moulla PAKALI

0 Likes
Message 6 of 14

tbrammer
Advisor
Advisor

@guillaume_aronica @metzdorf @Anonymous :

We ran into this issue when porting from AutoCAD 2020 to AutoCAD 2022.

Has someone found a solution in the meantime?
Switching to WebView as suggested by @astuy  is no option for us.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 7 of 14

metzdorf
Explorer
Explorer

Yes I found a solution. I changed my cefsharp implementation to use WebView2. 

It uses the engine from from the chromium based Edge. 

0 Likes
Message 8 of 14

CADbloke
Advocate
Advocate

You can use your own assemblies instead of getting stuck with the ones that ship with AutoCAD.  See https://stackoverflow.com/questions/38671641/could-not-load-file-or-assembly-newtonsoft-json-version... - put it in the startup method. Relevant codez that I use  for something similar in case dead link ...

/// <summary> Initializes thisCadtool in AutoCAD / BricsCAD. Runs when Tool is loaded</summary>
/// <seealso cref="AcRun.IExtensionApplication.Initialize()"/>
public void Initialize() // <= Sometimes the Intialize() fires more than once  http://www.theswamp.org/index.php?topic=13630.msg194036#msg194036
{
    try
    {
        AppDomain currentDomain = AppDomain.CurrentDomain;                               // wait for the app to be ready: https://www.keanw.com/2013/01/displaying-a-dialog-on-autocad-startup-using-net.html
        currentDomain.AssemblyResolve -= new ResolveEventHandler(MyResolveEventHandler); // <= Sometimes the Intialize() fires more than once
        currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); // https://forums.autodesk.com/t5/navisworks-api/could-not-load-file-or-assembly-newtonsoft-json/td-p/7028055?profile.language=en
        
         // ... more stuffs
     }
     catch (Exception ex)
     {
        App.Log.Error(ex, "Initialize() blew up");
     }
     
     /// <summary> Because AutoCAD hijacks the version of <c>JSON.NET</c> if you don't tell it to xxxx off</summary>
}    /// <remarks> https://forums.autodesk.com/t5/navisworks-api/could-not-load-file-or-assembly-newtonsoft-json/m-p/7460535#M3467 </remarks>> 
     /// <param name="sender"> Source of the event. </param>
     /// <param name="args">   Resolve event information. </param>
     /// <returns> <c>JSON.NET</c> </returns>
private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
    if (args?.Name?.Contains("Newtonsoft.Json") ?? false)
    {
        try
        {
            string assemblyFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Newtonsoft.Json.dll";
            return Assembly.LoadFrom(assemblyFileName);
        }
        catch (Exception e)
        {
            App.Log.Error(e, "FAILed loading JSON.NET"); // will probably fail because logger uses JSON.NET
            return null;
        }
    }
    else
        return null;
}

 

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
0 Likes
Message 9 of 14

981178411
Explorer
Explorer

Hello, I would like to ask whether there is a way to prohibit CAD loading Accef

0 Likes
Message 10 of 14

hamgeorge2015
Community Visitor
Community Visitor

Is there any update on the conflict between the Cefsharp and the AcCef?

0 Likes
Message 11 of 14

metzdorf
Explorer
Explorer

I have not followed this problem any more since I changed to WebView2.

0 Likes
Message 12 of 14

ceduca
Explorer
Explorer

@metzdorf 

Hello, how to proceed to use webview2?
I downloaded the SDK using NuGet. When it is an EXE application, it works perfectly and the site is shown in the webview, but when it is a DLL application for autocad, nothing is shown. The form only has the webview.

I'm using version 2023.
One image shows how the form is in visual studio, another shows when it is an EXE application (showing google) and another shows when it is a DLL in autocad (empty form).

What should I do? 

0 Likes
Message 13 of 14

metzdorf
Explorer
Explorer

Hi ceduca,

 

I believe you could have one of my initial problems:

- are all required dll's in the directory with you build dll? (Microsoft.Web.WebView2.Core.dll, Microsoft.Web.WebView2.WinForms.dll and WebView2Loader.dll)

- do you run the complete init in you dll in the right order? (CoreWebView2Environment.CreateAsync, WebView2.EnsureCoreWebView2Async)

 

A different problem could be the ResizeHandling. In my application was a problem the resize handling. After changing the panel size, was the browser empty.

 

I hope this helps a little bit.

Message 14 of 14

ceduca
Explorer
Explorer
Hi metzdorf!

Thanks for answering.

When used in an EXE, WebView2Loader.dll does not need to be in the same folder as the EXE, but when used in a DLL it does. I also changed the init order of CoreWebView2Environment.CreateAsync, WebView2.EnsureCoreWebView2Async.

Now it's working

Thank you!
0 Likes