Using the WebViewer2 package - Version issues

Using the WebViewer2 package - Version issues

grahamcook
Advocate Advocate
3,118 Views
9 Replies
Message 1 of 10

Using the WebViewer2 package - Version issues

grahamcook
Advocate
Advocate

Hi
I have just built in 2025 support for my plugin and hit on a specific issue with running Microsoft.Web.WebView2.  Digging deeper into the problem and trying all sorts of "fixes" I found that there seems to be a version dependency (I know that as of 2023, AutoCAD is dependent on Microsoft Edge WebView2 runtime being installed).
My 2024 version (.Net Framework) has worked all along but I've discovered ONLY if I have Microsoft.Web.WebView2 version 1.0.1020.30 installed.  If I install an older or newer version of Microsoft.Web.WebView2 then the plugin will complain that it cannot find 1.0.1020.30.
So, 2025 must have a similar issue as it gives a more generic error about a Microsoft.Web.WebView2.Wpf dependencies not being found.
If this is the case, is it possible to override this and target any version in my plugin?  Or, alternatively, how can I determine what version of the runtime AutoCAD 2025 is targeting so I can target the same version?

Thank you.

0 Likes
Accepted solutions (1)
3,119 Views
9 Replies
Replies (9)
Message 2 of 10

grahamcook
Advocate
Advocate

Just for completeness, here is the code and error I get in AutoCAD 2025 (on line that calls CoreWebView2Environment.CreateAsync).  This is the code behind of a xaml file that simply contains a WebView2 control:

Unable to load DLL 'WebView2Loader.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)'

The runtime folder does exist in the root of my plugin containing all the different platform builds of the loader dll.  The same code works in AutoCAD 2024 (with specific version of webview2) and Revit 2022-2025.  Just AutoCAD 2025 not working which is frustrating!

using Microsoft.Web.WebView2.Core;
using System;
using System.Windows;
using System.Windows.Controls;

namespace ArtisanCore.WPFControls
{
    /// <summary>
    /// Interaction logic for WebControl.xaml
    /// </summary>
    public partial class WebControl : UserControl
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="objIdOrUrl">The objectId of the plant item we need to show characteristics for OR a complete URL</param>
        public WebControl(string objIdOrUrl)
        {
            InitializeComponent();

            try
            {
                InitializeAsync();

                if (objIdOrUrl.StartsWith("https"))
                {
                    Wv.Source = new Uri(objIdOrUrl);
                }
                else
                {
                    // use the objIdOrUrl to determine teh url...
                    Wv.Source = new Uri(enter url here);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:\r\r" + ex.Message, "Web Load Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        // called from Window Constructor after InitializeComponent()
        // note: the `async void` signature is required for environment init
        async void InitializeAsync()
        {
            var userDataFolder = Session.Current.AppDataFolderACAD;

            // must create a data folder if running out of a secured folder that can't write like Program Files
            var env = await CoreWebView2Environment.CreateAsync(null, userDataFolder);

            // NOTE: this waits until the first page is navigated - then continues
            //       executing the next line of code!
            await Wv.EnsureCoreWebView2Async(env);
        }
    }
}
0 Likes
Message 3 of 10

grahamcook
Advocate
Advocate

The issue with AutoCAD 2024 loading only one version of the WebView2 control was a user error which has been sorted.

But the problem still persists with getting WebView2 to run in AutoCAD 2025.

Hoping that someone might be able to shed light on this as it is preventing us from issuing a 2025 version of our plugin.  I attach a very simple Visual Studio solution that contains 2 identical projects in regards to their functionality.  They each have one command, TestWebView2, which demonstrates the problem.  It simply loads a WPF form with a WebView2 control and loads the google home page.  One for 2024 that works fine, and one for 2025 (upgraded to Core of course).  2025 version will crash AutoCAD.

As I said previously, I have successfully upgraded several Revit AddIns to 2025 that use the WebView2 control with no problems but have hit a dead end regarding AutoCAD 2025.  Have tested on 2 systems and both result in a crash.

Any insight would very much be appreciated?

0 Likes
Message 4 of 10

Ed__Jobe
Mentor
Mentor

Are you an ADN member? If not, @moogalm might be able to take a look at it.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 10

grahamcook
Advocate
Advocate

Yes, I have a ADN membership.  I'll could request support via that then and post back any findings.

0 Likes
Message 6 of 10

Ed__Jobe
Mentor
Mentor

@grahamcook wrote:

Yes, I have a ADN membership.  I'll could request support via that then and post back any findings.


They're a bit slower than the forums, but you will definitely get an answer.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 10

moogalm
Autodesk Support
Autodesk Support
Accepted solution

Thanks @Ed__Jobe for mention, 

Hi @grahamcook 

 

You need to build you application explicitly for Win-x64 runtime, WebView components provided native C++ build dlls for all platforms like x64, Unix etc.
In the *.csproj file, add  win-x64

 

 <PropertyGroup>
   <TargetFramework>net8.0-windows</TargetFramework>
   <OutputType>Library</OutputType>
   <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
   <AssemblySearchPaths>D:\ArxSdks\Arx2025\inc;$(AssemblySearchPaths)</AssemblySearchPaths>
   <UseWPF>true</UseWPF>      
   <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
   <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
   <Platforms>x64;AnyCPU</Platforms>
   <RuntimeIdentifier>win-x64</RuntimeIdentifier>
 </PropertyGroup> 

 

moogalm_0-1723096088466.png

 

 

Message 8 of 10

graham
Participant
Participant

Thank you Madhukar!
I did try that before posting to the forums through the project properties UI.

graham_0-1723099023754.png

But that didn't add the RuntimeIdentifier tag (just the PlatformTarget tag).  Adding that in manually as in your example resolved the issue.
I don't understand why my Revit 2025 AddIn's don't need the same tag, they just work off the bat.
Anyway, it's now working and we can move forwards so thank you and thank you @Ed__Jobe  for asking @moogalm to look into!

0 Likes
Message 9 of 10

moogalm
Autodesk Support
Autodesk Support

Revit probably ships with WebView2Loader.dll. I know that Revit has an intrinsic dependency on WebView2, so your app doesn't get a chance to probe your debug folder; it finds it in the Revit install folder.

On the other hand, AutoCAD has no dependency on WebView2 as an in-process module, probably due to its unopinionated architecture, which delegates decision-making to users or developers.

 😊

0 Likes
Message 10 of 10

Ed__Jobe
Mentor
Mentor

@moogalm wrote:

Thanks @Ed__Jobe for mention, 

 


@moogalm  ...and thanks for supporting the forums!

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes