WebView2 #xpa #dotnet


Frederik Soete
 

Hi group,

FYI. One little icky bug with my code: at some times the browser is not init'ed fast enough, so setting the Source property fails with a null reference exception. In order to solve that, I've recuperated the "CustomWait" function from Craig Martin's WebView2 project. I don't really understand its hocus pocus completely, but it seems to function as a good enough "await" alternative. So hats off to Craig.

Bye,

FS


Frederik Soete
 

Hi,

And the really nice part of this quest is discovering Microsoft has a "unique" way of telling us the app folder cannot be written. The error log just spits out a hair-raising message about a NullReferenceException.

Thanks for listening and sympathizing,

Frederik Soete


Frederik Soete
 

Hi everybody,

I have figured out my issue.

Initializing the browser will fail if our "user data folder location" is not writable.

By default the browser will try to put this location inside the Magic folder, but on our W11 computer this folder was not writable.

Solution in C# code (to put before the update of the source property of the brws object):

        // Initializing the browser will fail if our user data folder location (app folder) is not writable.
        // Prepare the browser environment by creating a custom app folder in the user's roaming profile directory.
        // If all goes well, brws.CoreWebView2 will not be null any more at end of this code segment (= browser has been init'ed).
        if (brws.CoreWebView2 == null) {
           
            // Get location of special folder (user's roaming profile directory).
            string app_data_roaming_folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            //System.Windows.Forms.MessageBox.Show(app_data_roaming_folder);
           
            // Append custom string to special folder location (subdirectory "MY_APP_FOLDER")
            string custom_app_folder = System.IO.Path.Combine(app_data_roaming_folder, "MY_APP_FOLDER");
            //System.Windows.Forms.MessageBox.Show("Wanted user data folder: " + custom_app_folder);
           
            // If necessary, create our custom app's folder. Ignore errors.
            try {
                System.IO.Directory.CreateDirectory(custom_app_folder);
            } catch {}
    
            // We create a WebView2 Environment using the installed runtime, and using our custom app's folder.
            var T1 = Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(null, custom_app_folder);
            // Wait for the result of this call.
            var env = T1.Result;
           
            // Initialize browser with this environment.
            var T2 = brws.EnsureCoreWebView2Async(env);
           
        }

        // Set Source property (in theory, this could also initialize the browser, but we have already done that).
        var uri = new Uri(new_url);
        brws.Source = uri;


Frederik Soete
 

Hi everybody,

I've got some more info now:
- Test app works flawlessly on W10, but not on W11.
- Test app also does not work on a W2022 terminal server.
- Edge WebView2 runtime is recent on every computer inspected.
- WebView2 SDK version we used is "Microsoft.Web.WebView2.1.0.1518.46".

Weird. I must be overlooking something crucial. I should not have to install an Edge Canary in a production environment, I think.

Bye,

FS


Frederik Soete
 

Hi, Adrian,

Isn't edge canary for experimental features? So do you install that on a non-developer computer? Or what do you do install there? The W11 appears to already have the Evergreen channel edge. (At least so far as we can tell, beginners that we are...)

Strange thing is: the version number IS detected on the W11. Both via registry and via SDK function. So you'd expect everything to work there, but alas!

We plan to have another go on another W11 computer, to see if that gives us a different outcome.

Anyhow, thx

FS

Op wo 25 jan. 2023 19:14 schreef Adrian Wick <adrian.wick2015@...>:

Hi Frederik,

did you install edge canary (https://www.microsoftedgeinsider.com/en-us/download) on windows 11 where you are running the app for the user logged into the windows?

Regards,
A


Adrian Wick
 

Hi Frederik,

did you install edge canary (https://www.microsoftedgeinsider.com/en-us/download) on windows 11 where you are running the app for the user logged into the windows?

Regards,
A


Frederik Soete
 
Edited

Hi everybody,

I am indeed late to the WebView2 party. Are there any caveats with regard to deployment? See below Windows 10 versus 11?

Our testing app consists of:
- XPA 3.3k (32-bit)
- A derivative of Craig Martin's code
- Components.xml similar to Adrian Wick's.
- "Microsoft.Web.WebView2.WinForms.dll" can be found in a dedicated app DLL directory.
- "Microsoft.Web.WebView2.Core.dll" can be found in a dedicated app DLL directory.
- "WebView2Loader.dll" (x86) is in the same folder as both these assemblies.

Conclusions:
- On Windows 10 everything is fine: both on the original development workstation, as on another co-worker's workstation. Nothing special has been added, except by Windows itself.
- But on Windows 11, on another co-worker's workstation the same app gives a null reference exception on pressing the GO button.

Can someone offer guidance as to what could be going on? Is something missing from a fresh Windows 11? Other clues?

Thanks in advance,

Frederik Soete


Avgerinos
 

Thanks Roberto and Andrian for the suggestions.

Tried both hints in XPA3.3 & 4.7, but no luck yet.
It always ends up with the following message in mgerror.log: The instance of CoreWebView2 is uninitialized and unable to complete this operation. See EnsureCoreWebView2Async., Program: "TEST__u_IExplorer_.NET_WebView".

It's probably a matter of runtimes & paths setup.
Anyone can describe the exact steps taken to install WebView2 libraries?

Thanks in advance to anyone who can help
Regards
Avgerinos

On 5/9/2022 5:20 μ.μ., Adrian Wick wrote:

Install the microsoft edge cannary. That did the trick for me.

regards
A


Adrian Wick
 

Install the microsoft edge cannary. That did the trick for me.

regards
A


Roberto Gauer
 

Hi Avgerinos! 

Look for WebView2Loader.dll (x86) and place it on the same folder from others MS libs.

This file comes from nuget package, on runtimes folder.


On Mon, Sep 5, 2022 at 1:41 AM Avgerinos <mento@...> wrote:
Hi Adrian & Craig

Still struggling to make it work...
The WebView2 .net control seems to load, but displays only a blank page (without errors).

Which version of .NET framework did you have installed?

Regards
Avgerinos


On 16/4/2022 6:32 μ.μ., Adrian Wick wrote:
Oh boy ... I FINALLY DID IT!

This is all you need guys:





Now I can go have a beer.

Happy holidays everyone!

Regards
A


Avgerinos
 

Hi Adrian & Craig

Still struggling to make it work...
The WebView2 .net control seems to load, but displays only a blank page (without errors).

Which version of .NET framework did you have installed?

Regards
Avgerinos


On 16/4/2022 6:32 μ.μ., Adrian Wick wrote:

Oh boy ... I FINALLY DID IT!

This is all you need guys:





Now I can go have a beer.

Happy holidays everyone!

Regards
A


Adrian Wick
 

Oh boy ... I FINALLY DID IT!

This is all you need guys:





Now I can go have a beer.

Happy holidays everyone!

Regards
A


Adrian Wick
 

Does anyone know where to get Microsoft.Web.dll?

So here are the steps i did:
1. installed visual studio 2019 (i don't think this was a mandatory step, but i did it anyway)
2. installed edge (the evergreen bootstrap and evergreen stand alone; i also downloaded the fixed version, extracted it into a folder ... i don't know what else to do with the extracted files)
3. installed edge canary (https://www.microsoftedgeinsider.com/en-us/download)
4. downloaded the webview2 from github and nuget ...

and when i run the webview2 xpa sample i still get errors in components sections. so i manually search for dlls ... i find each dll except for the microsoft.web.dll file and when i run the application
i get error that assembly microsoft.web.dll could not be found or loaded ...

regards
A


Adrian Wick
 

Craig thank you for taking the time to help me!

1st i found out that i get 2 different "extractions". I have winrar installed and by default the .cab file was opened with this program.
If i extract using this program, i get this content with directories!


than i did the same with windows explorer:


i get 2 totaly different results ... and not in single one of those two extractions are there files which are in your project CRR:
- Microsoft.Web.dll
- Microsoft.Web.WebView2.Core.dll
- Microsoft.Web.WebView2.WinForms.dll

I found last two on github. But i cant find 1st one Microsoft.Web.dll ...

Regards,
A


Craig Martin
 

I'll need to revisit my notes, because I used an installer I think you can see from 

They can be anywhere but you'd need to change the CRR to reflect that location.
It's been a few months and the world got busy, I'll verify my steps again soon.


From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Jim Stephenson <jstephen@...>
Sent: Thursday, March 10, 2022 2:13 PM
To: main@magicu-l.groups.io <main@magicu-l.groups.io>
Subject: Re: [magicu-l] WebView2 #xpa #dotnet
 
Craig, where should the contents be extracted to?

On Thu, Mar 10, 2022 at 3:09 PM Craig Martin <craig@...> wrote:
Couple of way but easiest is you can right-click and extract the contents.

From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Adrian Wick <adrian.wick2015@...>
Sent: Thursday, March 10, 2022 10:33 AM
To: main@magicu-l.groups.io <main@magicu-l.groups.io>
Subject: Re: [magicu-l] WebView2 #xpa #dotnet
 
Hm,

how do i install cab file? I must have done something wrong with this ...

regards,
A


Jim Stephenson
 

Craig, where should the contents be extracted to?


On Thu, Mar 10, 2022 at 3:09 PM Craig Martin <craig@...> wrote:
Couple of way but easiest is you can right-click and extract the contents.

From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Adrian Wick <adrian.wick2015@...>
Sent: Thursday, March 10, 2022 10:33 AM
To: main@magicu-l.groups.io <main@magicu-l.groups.io>
Subject: Re: [magicu-l] WebView2 #xpa #dotnet
 
Hm,

how do i install cab file? I must have done something wrong with this ...

regards,
A


Craig Martin
 

Couple of way but easiest is you can right-click and extract the contents.


From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Adrian Wick <adrian.wick2015@...>
Sent: Thursday, March 10, 2022 10:33 AM
To: main@magicu-l.groups.io <main@magicu-l.groups.io>
Subject: Re: [magicu-l] WebView2 #xpa #dotnet
 
Hm,

how do i install cab file? I must have done something wrong with this ...

regards,
A


Adrian Wick
 

Hm,

how do i install cab file? I must have done something wrong with this ...

regards,
A


Adrian Wick
 

I have downloaded the files and i have the same problem as i did with my application.
The dotnet object placed on the form is shown if i look it in generator. But when i try to run the problem, nothing is shown ... no error or anything.

F8 on the program also gives no error.

Regards
A


Craig Martin
 

In some ways, this is a little academic since 4.8 now embeds CEFSharp but WebView2 is far more versatile, robust and better supported. I wouldn't be surprised if MSE swap to this in an upcoming release.
I have no special information on any of their cunning plans, however.


From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Adrian Wick <adrian.wick2015@...>
Sent: Tuesday, March 8, 2022 10:51 AM
To: main@magicu-l.groups.io <main@magicu-l.groups.io>
Subject: Re: [magicu-l] WebView2 #xpa #dotnet
 
Thank you! I'll have a look tomorrow and report back to you!

regards,
A