question

MauricioKorbman-7803 avatar image
1 Vote"
MauricioKorbman-7803 asked DanielZhang-MSFT answered

Windows WebView2 access local files exception raised

I am testing the WebView2 control and want to access local files instead of presenting a remote website. I am using the SetVirtualHostNameToFolderMapping method but get an exception specifying that the interface is not support maybe because an old version of the control or an old version of the runtime. I am using the most recent version of both (88.0.705.81 for the runtime and 1.0.790 for the WebView control) so not sure why I get the exception. Any help/ideas? This is the line of code I get the exception on: webView.CoreWebView2.SetVirtualHostNameToFolderMapping("web.example","web",CoreWebView2HostResourceAccessKind.Allow); This is the exception I get: An unhandled exception of type 'System.NotImplementedException' occurred in Microsoft.Web.WebView2.Core.dll Unable to cast to Microsoft.Web.WebView2.Core.Raw.ICoreWebView2_3. This may happen if you are using an interface not supported by the version of the WebView2 Runtime you are using. For instance, if you are using an experimental interface from an older SDK that has been modified or removed in a newer runtime. Or, if you are using a public interface from a newer SDK that wasn't implemented in an older runtime.

windows-forms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

Hi MauricioKorbman-7803,
From this document, we can see that CoreWebView2.SetVirtualHostNameToFolderMapping() method applies to WebView2 .NET Prerelease 1.0.721 or 1.0.790.
And the offical document said 1.0.790-prerelease and 1.0.721-prerelease is used for microsoft edge version 86.0.616.0 or newer.
So it is recommended to use the Canary channel when developing using the prerelease packages.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.