Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: v1.0.1722.32 doesn't get past EnsureCoreWebView2Async #3375

Closed
RickStrahl opened this issue Apr 10, 2023 · 18 comments
Closed

Bug: v1.0.1722.32 doesn't get past EnsureCoreWebView2Async #3375

RickStrahl opened this issue Apr 10, 2023 · 18 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@RickStrahl
Copy link

RickStrahl commented Apr 10, 2023

I just switched one of my samples to use the latest WebView (to v1.0.1722.32 from v1.0.1661.34 and noticing that the latest version is failing by not completing the load operation.

Specifically WebBrowser.EnsureCoreWebView2Async(env) fails to ever complete - the call is made and it hangs without ever continuing which of course keeps content from loading.

Here's the relevant code, which is called from the host form's ctor, with a wrapping WebViewHandler. This fails with v1.0.1722.32 but works just fine with v1.0.1661.34:

      protected async Task InitializeAsync()
        {
            if (string.IsNullOrEmpty(WebViewEnvironmentFolder))
            {
                WebViewEnvironmentFolder = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "_WebView");
            }

            if (!IsInitialized)  // Ensure this doesn't run more than once
            {
                // must create a data folder if running out of a secured folder that can't write like Program Files
                var env = await CoreWebView2Environment.CreateAsync(
                    userDataFolder: WebViewEnvironmentFolder
                );

               // *** THIS HANGS IN v1.0.1722.32 - works in v1.0.1661.34
                await WebBrowser.EnsureCoreWebView2Async(env);
                IsInitialized = true;
            }

If you want to try this out you can find the code here:

Westwind.WebView Component Github Repo

You can clone the project, and run the WPF Sample. Click on the Emojii Viewer.

The Westwind.WebView control project for now uses v1.0.1661.34 and the EmojiiViewer works fine. Then change the WebView version to v1.0.1722.32, recompile and re-run and you'll see the application hang or rather not draw the emoji view which is what displays in the WebView.

The relevant code lives in Westwind.WebView.WebViewHandler::InitializeAsync() which exhibits the hanging situation.

AB#44135105

@RickStrahl RickStrahl added the bug Something isn't working label Apr 10, 2023
@RickStrahl RickStrahl changed the title Bug: v1.0.1722.32 doesn't get past Bug: v1.0.1722.32 doesn't get past EnsureCoreWebView2Async Apr 10, 2023
@novac42
Copy link
Contributor

novac42 commented Apr 11, 2023

Thanks for reporting the issue. I've assigned this to a dev that can help follow up on this.

@dmcgloin
Copy link

I believe I am seeing a similar issue. Happened when I updated to v1.0.1722.32 from v1.0.1661.34. My code throws an exception when calling EnsureCoreWebView2Async. The exception details:

"Method not found: 'Void Microsoft.Web.WebView2.Core.CoreWebView2Profile.add_Deleted(System.EventHandler`1<System.Object>)'."} | System.Exception {System.MissingMethodException}"

@LiangTheDev LiangTheDev added the tracked We are tracking this work internally. label Apr 11, 2023
@champnic
Copy link
Member

champnic commented Apr 11, 2023

Hey all - Thanks for reaching out, and sorry you're hitting this. We're looking into this ASAP and will consider deprecating the current SDK if this turns out to be widespread. I just tried to repro in a Winforms app using 1.0.1722.32 and runtime 112.0.1722.39 and didn't see this crash or hang.

Can you share what runtime versions you are seeing this with? And is there any other specific context necessary, like running under a debugger, or breaking on handled exceptions? Thanks!

@RickStrahl
Copy link
Author

RickStrahl commented Apr 11, 2023

Using the latest runtimes as of yesterday (112.0.1722.39 is what I have).

From what I can tell the runtime doesn't matter - it's the .NET library that's causing the problem since reverting back to the prior version makes it work. This is in WPF applications.

I've just double checked both of my commercial desktop apps, and they are showing the same behavior. Here's Markdown Monster starting up and failing to load the two WebViews with 1.0.1722.32. Go back to v1.0.1661.34 and everything runs fine.

image

The GitHub sample app should demonstrate. Installed version runs - change the WV version and it stops working.

@dmcgloin
Copy link

dmcgloin commented Apr 11, 2023

Thanks for investigating. Seeing this in Debug or Release builds, with or without debugger attached.

I've also uninstalled + reinstalled the WebView2 runtime.

@champnic
Copy link
Member

I get a consistent repro on my WPF sample app as well, crashing on add_Deleted. In Winforms I can get it to break on remove_Deleted if I change the breakpoint settings in VS, though if I continue it's a handled exception and works fine. We think we've identified the checkin that broke this and are working with the dev, though also trying to understand and root cause the failure more fully.

@dmcgloin
Copy link

dmcgloin commented Apr 11, 2023

Full stack: (actually, I'm a bit confused. I think this is a second failure when trying to recover or something?).

Unhandled Exception: System.MissingMethodException: Method not found: 'Void Microsoft.Web.WebView2.Core.CoreWebView2Profile.remove_Deleted(System.EventHandler`1<System.Object>)'.
   at Microsoft.Web.WebView2.Wpf.WebView2.Uninitialize(Boolean browserCrashed)
   at Microsoft.Web.WebView2.Wpf.WebView2.Dispose(Boolean disposing)
   at System.Windows.Interop.HwndHost.WeakEventDispatcherShutdown.OnShutdownFinished(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Threading.Dispatcher.ShutdownImplInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.Dispatcher.ShutdownImpl()
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at AuthorizationExample.App.Main()

@RickStrahl
Copy link
Author

RickStrahl commented Apr 11, 2023

The error trace I see in my logs looks like this:

4/10/2023 2:48:56 PM - App: Method not found: 'Void Microsoft.Web.WebView2.Core.CoreWebView2Profile.remove_Deleted(System.EventHandler`1<System.Object>)'.
Method not found: 'Void Microsoft.Web.WebView2.Core.CoreWebView2Profile.remove_Deleted(System.EventHandler`1<System.Object>)'.
Markdown Monster v2.8.14.0
10.0.22621.1.amd64fre.ni_release.220506-1250 - en-US - NET 4.8 - 64 bit
Dell Inc. XPS 15 9520, NVIDIA GeForce RTX 3050 Laptop GPU, hw-acc: False
en-US - en-US    
---
Microsoft.Web.WebView2.Wpf
   at Microsoft.Web.WebView2.Wpf.WebView2.Uninitialize(Boolean browserCrashed)
   at Microsoft.Web.WebView2.Wpf.WebView2.Dispose(Boolean disposing)
   at MarkdownMonster.Windows.EditorAndPreviewPane.Release() in D:\projects\MarkdownMonsterCode\MarkdownMonster\Windows\EditorPane\EditorAndPreviewPane.xaml.cs:line 38
   at MarkdownMonster.MarkdownDocumentEditor.ReleaseEditor() in D:\projects\MarkdownMonsterCode\MarkdownMonster\_Classes\MarkdownDocumentEditor.cs:line 314
   at MarkdownMonster.MainWindow.<CloseTab>d__84.MoveNext() in D:\projects\MarkdownMonsterCode\MarkdownMonster\MainWindow.xaml.cs:line 1987
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MarkdownMonster.MainWindow.<TabControl_TabItemClosingItemCallback>d__76.MoveNext() in D:\projects\MarkdownMonsterCode\MarkdownMonster\MainWindow.xaml.cs:line 1557
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
System.MissingMethodException
---------------------------

Looks like here too it's remove_deleted where the problem comes up.

From what I can tell it looks like it has to do with the environment folder not being created. I've tried with different paths just to see if it might be some weird permissions issue, but whether I provide a folder, or use the default global folder doesn't make a difference - it hangs either way.

@RickStrahl
Copy link
Author

What's interesting that I see mostly hanging operations - IOW it hits the await WebBrowser.EnsureCoreWebView2Async(env) and just hangs and never gets past it. But then I also see the exceptions in my log that @dmcgloin is reporting although I tend to not see those exceptions bubbling up into the UI as they should - possibly the latter is happening when the app is eventually killed (it won't shut down via any normal shutdown operations).

@champnic
Copy link
Member

I think we've root-caused the issue, including why it's not an issue on Winforms. It's related to being unable to catch MissingMethodExceptions in a simple try-catch. We have a potential fix that I'm validating now.

Given this seems to be hitting WPF WebView2 100% we'll be moving forward with the deprecation of the 1.0.1722.32 SDK and releasing a new one hopefully soon.

@RickStrahl
Copy link
Author

Thanks you for the quick turnaround @champnic!

It's related to being unable to catch MissingMethodExceptions in a simple try-catch.

But it works in WinForms? That seems like it would be a runtime/language issue independent of the UI platform?

@champnic
Copy link
Member

But it works in WinForms? That seems like it would be a runtime/language issue independent of the UI platform?

The code is actually different in the two UI platforms, so my fix is to bring the missing code from the Winforms control to the WPF control. It looks like it's working, so now we'll work on getting it checked in and released in a new SDK package.

@dmcgloin
Copy link

Really appreciate the WebView2 team's quick response and investigation on this issue. We work with a lot of different companies which don't come anywhere close to the level of responsive and diligence shown here. Well done!

@RickStrahl
Copy link
Author

Just to confirm latest version v1.0.1722.45 fixes the problem and everything is working as expected once again.

Thanks for getting this fixed quickly.

Aloha...

@jukea
Copy link

jukea commented Dec 18, 2023

Hi !
I seem to hit a variation of this issue with 1.00.2151.40. The Exception is reported in the console output :

Exception thrown: 'System.MissingMethodException' in Microsoft.Web.WebView2.Wpf.dll
Reported on this line in EnsureCoreWebView2Async's internal async Init method :

try
{
RegisterProfileDeletedEvent(register: true, CoreWebView2);
}
catch (Exception)
{
}

The main symptom is that the webView never displays anything, and it seem to derail the initialization of the xaml Control it is part of, but I get no other error / exception.

The exception is supposed to be caught, so it should not be reported in the Console output ?
But then it was said earlier that the issue was "related to being unable to catch MissingMethodExceptions in a simple try-catch. ",
and seeing how the call to RegisterProfileDeletedEventis still in a try catch block, could the fix have been reverted ?

@LiangTheDev
Copy link
Member

Could you try to update to 1.0.2210.55?

The try-catch was still there in 2151, however MissingMethodExceptions sometimes could not be caught by simple try-catch. The issue should go away in newer 2210 SDK where the related API has been promoted to stable public API and is not missing method any more.

@jukea
Copy link

jukea commented Dec 18, 2023

Thanks for the quick answer, I will try and report back

@jukea
Copy link

jukea commented Dec 18, 2023

Amazing, it worked, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

6 participants