PowerToys: peek bug

Microsoft PowerToys version

0.85.1

Installation method

Microsoft Store

Running as admin

Yes

Area(s) with issue?

Peek

Steps to reproduce

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x8007139F): 组或资源的状态不是执行请求操作的正确状态。 (0x8007139F)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateCoreWebView2ControllerAsync(IntPtr ParentWindow)
   at Microsoft.Web.WebView2.WinForms.WebView2.InitCoreWebView2Async(CoreWebView2Environment environment, CoreWebView2ControllerOptions controllerOptions)
   at Microsoft.PowerToys.PreviewHandler.Monaco.MonacoPreviewHandlerControl.<>c__DisplayClass13_0`1.<<DoPreview>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at InvokeStub_SendOrPostCallback.Invoke(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)


************** Loaded Assemblies **************
System.Private.CoreLib
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Private.CoreLib.dll
----------------------------------------
PowerToys.MonacoPreviewHandler
    Assembly Version: 0.85.1.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PowerToys.MonacoPreviewHandler.dll
----------------------------------------
System.Runtime
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Runtime.dll
----------------------------------------
WinRT.Runtime
    Assembly Version: 2.1.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\WinRT.Runtime.dll
----------------------------------------
System.Collections
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Collections.dll
----------------------------------------
System.Collections.Concurrent
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Collections.Concurrent.dll
----------------------------------------
System.Runtime.InteropServices
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Runtime.InteropServices.dll
----------------------------------------
System.Drawing.Primitives
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Drawing.Primitives.dll
----------------------------------------
PowerToys.ManagedCommon
    Assembly Version: 0.85.1.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PowerToys.ManagedCommon.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Windows.Forms.dll
----------------------------------------
PowerToys.PreviewHandlerCommon
    Assembly Version: 0.85.1.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PowerToys.PreviewHandlerCommon.dll
----------------------------------------
System.ComponentModel.Primitives
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.ComponentModel.Primitives.dll
----------------------------------------
System.Windows.Forms.Primitives
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Windows.Forms.Primitives.dll
----------------------------------------
System.Collections.Specialized
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Collections.Specialized.dll
----------------------------------------
WindowsBase
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\WindowsBase.dll
----------------------------------------
PowerToys.Common.UI
    Assembly Version: 0.85.1.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PowerToys.Common.UI.dll
----------------------------------------
System.IO.Abstractions
    Assembly Version: 17.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.IO.Abstractions.dll
----------------------------------------
System.Security.AccessControl
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Security.AccessControl.dll
----------------------------------------
System.Diagnostics.TraceSource
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Diagnostics.TraceSource.dll
----------------------------------------
System.Diagnostics.TextWriterTraceListener
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Diagnostics.TextWriterTraceListener.dll
----------------------------------------
System.Diagnostics.FileVersionInfo
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Diagnostics.FileVersionInfo.dll
----------------------------------------
System.Threading
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Threading.dll
----------------------------------------
System.Drawing.Common
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Drawing.Common.dll
----------------------------------------
Microsoft.Win32.Primitives
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\Microsoft.Win32.Primitives.dll
----------------------------------------
System.ComponentModel.EventBasedAsync
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.ComponentModel.EventBasedAsync.dll
----------------------------------------
System.Threading.Thread
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Threading.Thread.dll
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\Accessibility.dll
----------------------------------------
Microsoft.Win32.SystemEvents
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\Microsoft.Win32.SystemEvents.dll
----------------------------------------
System.Memory
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Memory.dll
----------------------------------------
System.Diagnostics.StackTrace
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Diagnostics.StackTrace.dll
----------------------------------------
System.Text.Encoding.Extensions
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Text.Encoding.Extensions.dll
----------------------------------------
ControlzEx
    Assembly Version: 6.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\ControlzEx.dll
----------------------------------------
PresentationCore
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PresentationCore.dll
----------------------------------------
PresentationFramework
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PresentationFramework.dll
----------------------------------------
DirectWriteForwarder
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\DirectWriteForwarder.dll
----------------------------------------
System.Runtime.Extensions
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Runtime.Extensions.dll
----------------------------------------
System.Diagnostics.Debug
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Diagnostics.Debug.dll
----------------------------------------
System.Runtime.CompilerServices.VisualC
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Runtime.CompilerServices.VisualC.dll
----------------------------------------
System.Collections.NonGeneric
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Collections.NonGeneric.dll
----------------------------------------
System.ObjectModel
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.ObjectModel.dll
----------------------------------------
Microsoft.Win32.Registry
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\Microsoft.Win32.Registry.dll
----------------------------------------
System.ComponentModel.TypeConverter
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.ComponentModel.TypeConverter.dll
----------------------------------------
System.ComponentModel
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.ComponentModel.dll
----------------------------------------
System.Xaml
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Xaml.dll
----------------------------------------
System.Private.Uri
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Private.Uri.dll
----------------------------------------
System.Configuration.ConfigurationManager
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Configuration.ConfigurationManager.dll
----------------------------------------
System.Xml.ReaderWriter
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Xml.ReaderWriter.dll
----------------------------------------
System.Private.Xml
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Private.Xml.dll
----------------------------------------
System.Net.WebClient
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Net.WebClient.dll
----------------------------------------
System.Linq
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Linq.dll
----------------------------------------
PresentationFramework-SystemXml
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PresentationFramework-SystemXml.dll
----------------------------------------
Microsoft.Web.WebView2.Core
    Assembly Version: 1.0.2739.15
    Location: C:\Users\11535\AppData\Local\PowerToys\Microsoft.Web.WebView2.Core.dll
----------------------------------------
mscorlib
    Assembly Version: 4.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\mscorlib.dll
----------------------------------------
Microsoft.Web.WebView2.WinForms
    Assembly Version: 1.0.2739.15
    Location: C:\Users\11535\AppData\Local\PowerToys\Microsoft.Web.WebView2.WinForms.dll
----------------------------------------
System.Runtime.CompilerServices.Unsafe
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Runtime.CompilerServices.Unsafe.dll
----------------------------------------
System.Numerics.Vectors
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Numerics.Vectors.dll
----------------------------------------
PowerToys.MonacoPreviewHandler.resources
    Assembly Version: 0.85.1.0
    Location: C:\Users\11535\AppData\Local\PowerToys\zh-CN\PowerToys.MonacoPreviewHandler.resources.dll
----------------------------------------
System.Drawing
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Drawing.dll
----------------------------------------
PowerToys.Settings.UI.Lib
    Assembly Version: 0.85.1.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PowerToys.Settings.UI.Lib.dll
----------------------------------------
System.Security.Principal.Windows
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Security.Principal.Windows.dll
----------------------------------------
System.Security.Claims
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Security.Claims.dll
----------------------------------------
System.Text.Json
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Text.Json.dll
----------------------------------------
System.Text.Encodings.Web
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Text.Encodings.Web.dll
----------------------------------------
System.Runtime.Intrinsics
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Runtime.Intrinsics.dll
----------------------------------------
System.Reflection.Emit.Lightweight
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Reflection.Emit.Lightweight.dll
----------------------------------------
System.Reflection.Primitives
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Reflection.Primitives.dll
----------------------------------------
System.Reflection.Emit.ILGeneration
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Reflection.Emit.ILGeneration.dll
----------------------------------------
PowerToys.ManagedTelemetry
    Assembly Version: 0.85.1.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PowerToys.ManagedTelemetry.dll
----------------------------------------
System.Diagnostics.Tracing
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Diagnostics.Tracing.dll
----------------------------------------
PowerToys.FilePreviewCommon
    Assembly Version: 0.85.1.0
    Location: C:\Users\11535\AppData\Local\PowerToys\PowerToys.FilePreviewCommon.dll
----------------------------------------
UtfUnknown
    Assembly Version: 2.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\UtfUnknown.dll
----------------------------------------
System.Text.Encoding.CodePages
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Text.Encoding.CodePages.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.dll
----------------------------------------
System.Threading.ThreadPool
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Threading.ThreadPool.dll
----------------------------------------
System.Threading.Tasks
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Threading.Tasks.dll
----------------------------------------
System.Runtime.Loader
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Runtime.Loader.dll
----------------------------------------
System.Reflection.Metadata
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Reflection.Metadata.dll
----------------------------------------
System.Collections.Immutable
    Assembly Version: 8.0.0.0
    Location: C:\Users\11535\AppData\Local\PowerToys\System.Collections.Immutable.dll
----------------------------------------

************** JIT Debugging **************

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

Other Software

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17

Commits related to this issue

Most upvoted comments

@davidegiacometti This is interesting! When the WinUI3Apps\Assets\Monaco folder exists, the Monaco Preview Handler and Peek will resolve different MonacoDirectory paths because of the difference in where their executables are; Peek’s executable is under WinUI3Apps and PowerToys.MonacoPreviewHandler.exe lives a level up. This is fine if the WinUI3Apps\Assets\Monaco folder doesn’t exist, but FilePreviewCommon’s GetRuntimeMonacoDirectory() only checks the existence of Assets\Monaco relative to the executable’s location, not whether the Monaco asset files are present inside (which is a perfectly understandable assumption!). If there are issues during installation or after which end up creating this folder under WinUI3Apps then the issue will happen for Peek but it won’t affect the Explorer preview pane, as you saw in your repro.

I think the solution would be to do an explicit check that the executing assembly’s location is WinUI3Apps in GetRuntimeMonacoDirectory(). The issue can’t be fixed from within Peek’s code.

This would change the code in FilePreviewCommon.MonacoHelper.GetRuntimeMonacoDirectory to something like:

    private static string GetRuntimeMonacoDirectory()
    {
        string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;

        // If the executable is within "WinUI3Apps", correct the path first.
        if (Path.GetFileName(exePath) == "WinUI3Apps")
        {
            exePath = Path.Combine(exePath, "..");
        }

        string monacoPath = Path.Combine(exePath, "Assets", "Monaco");

        return Directory.Exists(monacoPath) ?
            monacoPath :
            throw new DirectoryNotFoundException($"Monaco assets directory not found at {monacoPath}");
    }

Of course, we still don’t know why the WinUI3Apps\Assets\Monaco folder was created in the first place on the user’s machine, but it’s a start ☺️

I will put a PR in to handle this.