Skip to content

System.ArgumentException when Window has TopMost and program running under auto elevated permission #486

@cuiliang

Description

@cuiliang

Description
Condition:

  • Window contains WebView2 has TopMost=true setted. In code or XAML.
  • Program has uiAccess="true" flag in manifest file.
  • Code sign program.
  • Start program from subfolders of 'c:\program files'

Exception: Value is not in the expected range

System.ArgumentException
   在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32, IntPtr)
   在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32)
   在 Microsoft.Web.WebView2.Core.CoreWebView2Environment+<CreateCoreWebView2ControllerAsync>d__20.MoveNext()
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   在 Microsoft.Web.WebView2.Wpf.WebView2+<>c__DisplayClass25_0+<<EnsureCoreWebView2Async>g__Init|0>d.MoveNext()
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   在 WpfApp2.MainWindow+<InitializeAsync>d__2.MoveNext()
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   在 System.Windows.Threading.DispatcherOperation.InvokeImpl()
   在 MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   在 MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   在 System.Windows.Threading.DispatcherOperation.Invoke()
   在 System.Windows.Threading.Dispatcher.ProcessQueue()
   在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   在 MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   在 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   在 MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   在 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   在 System.Windows.Application.RunDispatcher(System.Object)
   在 System.Windows.Application.RunInternal(System.Windows.Window)
   在 WpfApp2.App.Main()

code:

 public MainWindow()
        {
            InitializeComponent();

            InitializeAsync();
        }

        async void InitializeAsync()
        {

            try
            {
                var folder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Quicker",
                    "WebView2");
                var env = await CoreWebView2Environment.CreateAsync(null, folder).ConfigureAwait(true);
                await webView.EnsureCoreWebView2Async(env).ConfigureAwait(true);

                webView.UpdateWindowPos();

                webView.CoreWebView2.NavigateToString("<h1>Hello</h1>");

            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(ex.Message);
                sb.Append(ex.StackTrace);


                while (ex.InnerException != null)
                {
                    sb.Append("\n\n\n");
                    sb.AppendLine(ex.InnerException.Message);
                    sb.Append(ex.InnerException.StackTrace);
                    ex = ex.InnerException;
                }

                MessageBox.Show(sb.ToString());
            }
           
        }

Version
SDK: 0.9.628-prerelease
Runtime: 87.0.637.0
Framework: WPF with .Net 4.6.2
OS: Windows 10 2004(19041.450) , Windows 10 1909

Repro Steps

Screenshots

Additional context

AB#29614042

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtrackedWe are tracking this work internally.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions