Windows WebView2 access local files exception raised

Mauricio Korbman 6 Reputation points
2021-02-26T14:09:15.24+00:00

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
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,825 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,611 Reputation points
    2021-03-01T02:19:30.773+00:00

    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.

    0 comments No comments