Reputation: 13
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.
Upvotes: 1
Views: 1317
Reputation: 4377
SetVirtualHostNameToFolderMapping requires WebView2 Runtime version build 721 or newer. The feature is still in the prerelease SDK package and requires a recent canary channel Edge browser as your WebView2 Runtime.
You can see in the SetVirtualHostNameToFolderMapping docs the bottom of the page says it applies to SDK versions 1.0.721 and 1.0.790. And as the version doc notes, the WebView2 Runtime version that corresponds to an SDK version has a matching build number. So this new feature requires at least WebView2 Runtime version 89.0.721.0 or greater.
You are using the latest version of WebView2 Runtime which matches the stable channel of the Edge browser and the code for SetVirtualHostNameToFolderMapping hasn't made it to the stable channel yet. That's why its still only in our prerelease SDK package not the release SDK package. To try it out for now, you'll need to use the Edge browser canary channel as your WebView2 Runtime.
Upvotes: 1