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

Crash with "Run as admin" compatibility flag #2356

Closed
deemaseeq opened this issue Apr 12, 2022 · 6 comments
Closed

Crash with "Run as admin" compatibility flag #2356

deemaseeq opened this issue Apr 12, 2022 · 6 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@deemaseeq
Copy link

deemaseeq commented Apr 12, 2022

Description

I have an issue in WinForms application. We are using WebView2 to show some embedded video from the internet. WebView is always navigated to a fixed single page. It works fine, but in certain circumstances it crashes.

Specifically:

  • User logged in under default Administrator account.
  • On the executable file of application flag "Run this program as an administrator" under Properties -> Compatibility is set.

I've checked several things.

  • Any other account, even with exactly same rights and exactly same groups does not have this issue.
  • Using Right click -> "Run as administrator" to run the executable does not invoke this issue.
  • When the .exe has a shortcut and the option "Run as administrator" under Properties -> Shortcut -> Advanced can be set and it does not invoke this issue.
  • Updating WebView2 runtime does not fix the problem.
  • Updating WebView2 NuGet package does not fix the problem.
  • Changing the page to navigate changes nothing, component crashes even before the navigation happens.

Here is the exception:

System.InvalidOperationException: CoreWebView2 members cannot be accessed after the WebView2 control is disposed.
---> System.Runtime.InteropServices.COMException (0x8007139F): The group or resource is not in the correct state to perform the requested operation. (0x8007139F)
at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON reason)
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.MoveFocus(CoreWebView2MoveFocusReason reason)
--- End of inner exception stack trace ---
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.MoveFocus(CoreWebView2MoveFocusReason reason)
at Microsoft.Web.WebView2.WinForms.WebView2.OnGotFocus(EventArgs e)
at System.Windows.Forms.Control.WmSetFocus(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at Microsoft.Web.WebView2.WinForms.WebView2.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

Also, here is the data we got from ProcessFailed event:

CoreWebView2_ProcessFailed was invoked. Sender is Microsoft.Web.WebView2.Core.CoreWebView2.ExitCode: [18];
FrameInfosForFailedProcess: [];
ProcessDescription: [];
ProcessFailedKind: [RenderProcessExited];
Reason: [LaunchFailed];

I've omitted stack trace and loaded assemblies.

Also, I created sample project where just put WebView2 on the form to replicate the issue. I've included Crashpad folder from WebView2 data folder. There are some dumps there, which I'm not sure how to analyze. All I can tell is that error 0x0517A7ED is occurred.

Crashpad.zip

Version
We are running .NET 5, sdk version 5.0.405.
NuGet: 1.0.1150.38
Runtime: Fixed runtime supplied with the project. We used 93.0.961.47 at first, tried to update to 99.0.1150.46 but it didn't fixed the issue.
Framework: WinForms.
OS: Windows Server 2016 Standard 10.0.14393, Build 14393
Architecture: X64.

AB#39176451

@deemaseeq deemaseeq added the bug Something isn't working label Apr 12, 2022
@LiangTheDev
Copy link
Member

The dumps in the crashpad indicates that it is crashing due to repeatedly failed to launch GPU processing. Since the app also logged renderer process launch failure, I believe that this is the case where the security configurations on the server doesn't allow those sandboxed WebView2 child processes msedgewebview2.exe to be created. Try to see whether there are events from antivirus product or OS security components.
You can try to run the app with --edge-webview-switches=--no-sandbox to see whether that changes anything. Not that it is not recommended to use --no-sandbox command line switch as it is dangerous to run remote code without sandbox. This is just a test to verify a theory.
FWIW, I've tried to repro the issue on multiple machines with client Windows SKUs (latest Windows 10 down to RS5) and could not repro the issue.

@LiangTheDev
Copy link
Member

Thought about this again. If the app works normally, it should not be antivirus/security configuration related.
I do think that this is related to how we run the app process elevated. As Edge browser/webview2 could not run elevated, Edge code tries to detect whether the process is running elevated and try to de-elevate if it is detected. It seems that this detection is not working.
As I cannot repro this, either there are some differences between Windows client and server SKUs, or we are missing some information in the repro. Is there any other UAC related configuration on the machine, and are you able to repro this on other machines?

@LiangTheDev LiangTheDev added the tracked We are tracking this work internally. label Apr 21, 2022
@LiangTheDev
Copy link
Member

LiangTheDev commented Apr 22, 2022

@deemaseeq , we’ve made a change based on educated guess. Could you please try it out and see whether that works for you?

• Install Edge browser canary channel from Microsoft Edge Insider
• Set environment variable WEBVIEW2_RELEASE_CHANNEL_PREFERENCE as 1
• Try to run the scenario. If possible, verify that the msedgewebview2.exe is running from Edge canary installed location (%LOCALAPPDATA%\Microsoft\Edge SxS\Application\102.0.1236.0).

@deemaseeq
Copy link
Author

Hello, @LiangTheDev.
Sorry for the long response. Straight to the point - the change in Canary channel seems to fix the issue. With this runtime application runs properly regardless of the "Run as admin" flag.

I've also tried to investigate the issue more.
I had a suspicion that it is somehow related to GPU driver (we have Matrox G200eW3 on our machine) and tried to update it. Did not help, though.
It was possible to reproduce the issue on another machine with the same OS and the same hardware. However, I was not able to reproduce it on machine with Windows Server 2008 and different HW.

It was also possible to reproduce the issue with Microsoft Edge itself, Chrome and chromium. Firefox and Visual Studio Code also don't work properly when flag is set, although they do not crash, just fail to open anything.
And you were right - running the application with '--no-sandbox' option actually helps.

On every crash the event in Microsoft-Windows-UAC/Operational is generated. "The process failed to handle ERROR_ELEVATION_REQUIRED during the creation of a child process." with EventID: 1.

Thank you for the intervention, you guys are amazing.

@LiangTheDev
Copy link
Member

Thanks for all the details, and glad that the change works. We will now make the change for Edge WebView2 Runtime, probably in version 103.

@champnic
Copy link
Member

champnic commented Jun 9, 2022

This is fixed in runtime version 103.0.1254.0+. 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

3 participants