Windows WebView2 access local files exception raised - file

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.

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.
Finding the version
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.
Prerelease vs release package
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.

Related

Distribution of WebView2 user native NetForms App: is WebView2 Runtime really needed?

Due to end if IE life, I am replacing the WebBrowser (IE based) control in our native .net forms app (c#) to Microsoft.Web.WebView2.WinForms.WebView2.
The distribution page says, the user needs to install the WebView2 Runtime, which is about 100 MB!
My question, is this really needed? Isn't it enough to have the MS Edge installed (which is on EVERY Windows 10 machine)?
This page says:
Prerequisites: Ensure you install the following list of pre-requisites before proceeding. WebView2 Runtime or any Microsoft Edge Insider (preview) Channel (Beta, Dev, or Canary) installed on a supported OS (currently Windows 10, Windows 8.1, and Windows 7).
However, I am not sure if Edge Insider is a normal user's Edge Browser?
So, do I really need to distribute 100MB WebView2 Runtime (some of our customers are offline users) together with my App Installer (which uses WinForms.WebView2 control to display HTML pages inside my native App), or it's enough if MS Edge is installed on those systems?
The answer is: Yes, you need to install the WebView2 Runtime! The version of Edge installed on user's machines is NOT insider channel - it's the Stable channel.
Although you can use the Edge Insider channel, this is is not recommended except for developing, since only developers has this version.
To quote the page you linked to: "Microsoft Edge Stable channel isn't supported for WebView2".
Yes, you really need to distribute WebView2 Runtime. From the doc you link, you can find the reasons:
Under this paragraph Runtime or browser support during development or production, you can find that:
A production release of a WebView2 app can only use the WebView2 Runtime as the backing web platform, not Microsoft Edge.
The pre-installed browser on Windows 10 is Edge Stable Channel, most people won't install Edge Insider (preview) Channel, and:
Microsoft Edge Stable channel isn't supported for WebView2
Yes, include the WebView2 runtime in your distribution kit.
If you include the WebView2 Evergreen Bootstrapper in your kit, it will fetch the latest evergreen embedded browser. It's intended to be future-proof even if you don't update your kit for a while.
My kit installs correctly on W10, W7SP1, W8.1, WS2016, and WS2019 when I include the <2MiB bootstrapper and run it.
And, your installer can detect whether WebView2 is already installed, and skip reinstalling it. I hope everybody writing an installer will do that. If we do, then our users will be spared a reinstallation for each new WebView2-using app.
This little Inno Setup code stanza detects it correctly for me. Returns True when it's necessary to run the WebView2 installer.
function WebView2IsNotInstalled: Boolean;
var Pv: String;
var key64: String;
var key32: String;
begin
key64 := 'SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}';
key32 := 'SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}';
Result := True;
if RegQueryStringValue(HKEY_LOCAL_MACHINE, key64, 'pv', Pv) then
begin
Result := 0 = Length(pV);
end
else begin
if RegQueryStringValue(HKEY_LOCAL_MACHINE, key32, 'pv', Pv) then
begin
Result := 0 = Length(pV);
end;
end;
end;
(Please doublecheck this code: I am not an installer whizz.)

Microsoft Edge 84 released but WebView2 is not working as promised

I was waiting for Microsoft Edge 84 to be released so that WebView2 is included as they promise.. but after updating MEdge WebView2 is not working...
For example CoreWebView2Ready never fired and WebView2 is showing nothing and it is throwing exception on resize!!
WebView2 is working fine only when installing Canary channel version on target machine.
Any help will be appreciated.
Regards,
I've used 0.9.515-prerelease and as stated in https://learn.microsoft.com/en-us/microsoft-edge/webview2/releasenotes#09515-prerelease it requires Microsoft Edge 84 or higher.
In real it requires Evergreen WebView2 Runtime Installer to be distributed to work on the target machine.
The other way to make it work without WebView2 Runtime Installer is to install Canary channel on target machine which is now on version 86.
Regards,

No FontFamily element found in FontFamilyCollection

My WPF application suddenly fails with the following exception:
System.IO.FileFormatException: No FontFamily element found in
FontFamilyCollection that matches current OS or greater: Windows7SP1
I've tried different OS but it's happening only on Windows 7 with SP1.
Microsoft released an official statement about this issue here (includes workarounds):
https://github.com/dotnet/announcements/issues/53
I've found out that the exception is connected to the latest security update KB4055532. When this update is uninstalled on Windows 7 SP1 then the problem disappear.
Since I'm not allowed to comment:
Answer by 'user2250152' is correct.
#Comment by #Lieven Keersmaekers:
'fwiw - installing KB4056894 also triggers this exception when starting Powershell ISE':
I really doubt this.
I'm dealing with this 'KB4055532' issue for 2 days now on all in all 8 machines. But after having installed 'KB4056894' there were no issues with starting Powershell ISE.
This only started to happen after installing 'KB4055532'.
And uninstalling this 'KB4055532' (but still having 'KB4056894' on the machines) resolves the issue with Powershell.
Btw:
There is a hint on the following site (and a way to 'fix' the issue):
https://ngb.to/threads/32709-Microsoft-Patchday-Januar-2018-KB4055532-NET-Font-Probleme.
The issue comes from a '*.CompositeFont' file that gets replaced by the update and which is then missing information for Windows 7. This makes programs based on WPF using functions to determine FontFamily fail/crash.
Effectively I'm quite sure it is only the file 'GlobalUserInterface.CompositeFont' that must be exchanged to temporarily fix this issue.
I ran into this error with MarkdownPad2. With the information from .NET Framework January 2018 Rollup Known Issue KB4074906 - "TypeInitializationException" or "FileFormatException" error in WPF applications (thanks #Boris!), I used the manual repair option to download and replace the corrupted font (installed by Microsoft's update) and it solved the problem.
The exception looks like this:
The invocation of the constructor on type 'MarkdownPad2.UserControls.MarkdownEditor' that matches the specified binding constraints threw an exception.
---> System.TypeInitializationException: The type initializer for 'System.Windows.Media.Fonts' threw an exception.
---> System.IO.FileFormatException: No FontFamily element found in FontFamilyCollection that matches current OS or greater: Windows7SP1
Damaging a font during an upgrade seems like an inexcusable error. Apparently Microsoft agrees, as they closed the tech note with this comment:
All updates are extensively tested before they are provided to you. We are investigating the gap in our testing and will resolve that for our next release.

WDK Driver load issue (The service cannot be started, either because it is disabled)

I have used windows 8.1 to write many drivers with no issues when loading what so ever. There seems to be some sort of issue when I try to load a new basic KMDF driver that I built in visual studio. I am able to edit source and compile new versions of driver projects built while on previous versions of windows and I assume WDK would be the true culprit here. I am able to load drivers that the original project was generated in Windows 8.1 even if I edit the source and recompile, but specifically If I try to create a new driver project through visual studio, namely the example base for Kernel Mode Driver, it fails to load with the error :
"The service cannot be started, either because it is disabled or because it has no enabled devices associated with it"
A couple points :
The driver fails to load with the same error every time, I have my own certified trusted certificate from digicert and I have tried disabling driver signature enforcement, both with the same error. So it is safe to say that certificates is not the issue.
The only main difference I can tell between the old and new WDK sources is the old version specifically has versions of windows to build from, but the new has "universal" although through settings it looks like it will just build for Windows 10.
I am not doing any stupid errors meaning, I am compiling x64, etc...
I'm starting to think that the WDK KMDF basic template may have some sort of issue with it.
I would rather not have to gut an old project (driver) to get a successful "new" driver to load.
Can you please specify is it a legacy driver or a pnp driver.
I faced a similar issue, but the mistake I was doing was compiling a pnp driver and trying to load it as a legacy driver.
To specify the difference for completion sake pnp would be a driver that comes with a AddDevice routine. Such driver are expected to have a start type as 0 and are loaded at boot time. Need to attach the driver to a specific device object in the add device routine.
The legacy drivers are one with no AddDevice routine and we call IoCreateDevice from DriverEntry itself.

Silverlight: How Assembly version affects ApplicationSettengs

I am looking for information how IsolatedStorage.ApplicationSettings are affected by Assembly Version. Is there a way to specify version to get same ApplicationSettings for any version of same app?
According to Microsoft, the ApplicationSettings are per xap path, not assembly version:
Their scope is determined by the full path of the application .xap file
Checkout this MSDN article for more info.
Sounds like support for multiple browsers is known to be flaky.
You will also find that running your app in the Visual Studio dev server will have unexpected results if/when the port changes.

Resources