terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Context Menu -> Open in Windows Terminal -> "The server threw an exception"

Open ghost opened this issue 5 years ago • 34 comments

Note:

  1. Right Clicking on a folder and then opening the terminal works.
  2. Going inside the folder, then right clicking on empty space, and then opening the terminal gives error.
  3. I believe this was a known issue with older windows versions, that is why it was disabled earlier, but i think i saw a PR that implemented the functionality differently for older windows, but it is still not working for me
  4. I restarted explorer.exe, still gives the error. Maybe restarting the computer will make it work? I will try later and update the issue if it works. EDIT: Nope, still not fixed.

image

image

Environment

Windows build number: Microsoft Windows [Version 10.0.18363.1256]
Windows Terminal version: Windows Terminal Preview v1.6.10272.0

Any other software?: Not applicable

Steps to reproduce

Context Menu -> Open in Windows Terminal -> "The server threw an exception"

Expected behavior

It should work

Actual behavior

It doesn't

ghost avatar Jan 29 '21 07:01 ghost

The same is happening both with Preview (1.6.10272.0) and Stable (1.5.10271.0) release.

The Preview release writes the following error event in the Windows Registry (I have translated the message since my system language is Italian):

Name of application that generated the error: WindowsTerminal.exe, version: 1.6.2101.27002, timestamp: 0x6011c2d5
Name of module that generated the error: VCRUNTIME140.dll, version: 14.28.29334.0, timestamp: 0x5fa9a822
Exception code: 0xc0000005
Error offset 0x00000000000012de
ID of process that generated the error: 0x23e0
Start time of application that generated the error: 0x01d6f6121a1edfc5
Path of application that generated the error: C:\Program Files\WindowsApps\Microsoft.WindowsTerminalPreview_1.6.10272.0_x64__8wekyb3d8bbwe\WindowsTerminal.exe
Path of module that generated the error: C:\Program Files\WindowsApps\Microsoft.WindowsTerminalPreview_1.6.10272.0_x64__8wekyb3d8bbwe\VCRUNTIME140.dll
Report ID: 49018434-096f-4cef-bc1a-bd7dff740a23
Complete name of package that generated the error: Microsoft.WindowsTerminalPreview_1.6.10272.0_x64__8wekyb3d8bbwe
ID of application relative to the package that generated the error: App

The Stable release, on the other hand, keeps its secrets and doesn't write anything in the Windows Registry.

LucaBlackDragon avatar Jan 29 '21 07:01 LucaBlackDragon

Curious.

@axcadsd do you also have both the Stable and Preview versions of the Terminal installed? It might be helpful to get this crash dump:

/feedback

zadjii-msft avatar Jan 29 '21 11:01 zadjii-msft

Hi there!

Can you please send us feedback with the Feedback Hub with this issue and paste the link here so we can more easily find your crash information on the back end?

Thanks!

image image

ghost avatar Jan 29 '21 11:01 ghost

Curious.

@axcadsd do you also have both the Stable and Preview versions of the Terminal installed? It might be helpful to get this crash dump:

/feedback

Hi @zadjii-msft, I have sent a report with the Feedback Hub as instructed, after having uninstalled both Preview and Stable and performed a fresh install of Stable (unfortunately the issue remains). You can find it here: https://aka.ms/AAaz4tf I have also put the URL of this issue in the feedback description.

LucaBlackDragon avatar Jan 29 '21 12:01 LucaBlackDragon

@zadjii-msft I only use the Preview version, stable is not installed. Also, on my computer, the preview version is not creating any logs in the Event Viewer. Also, restarting the computer does not fix the issue.

Hopefully LucaBlackDragon's logs will help fix the issue.

ghost avatar Jan 29 '21 15:01 ghost

Huh, that got bucketed to 6c7b8911-e1ad-4e2c-4d48-c5aa5aacca38, but unfortunately the crash dump doesn't have anything useful in it. Just a single useless stack frame for diagtrack.dll in svchost.exe. That doesn't mean anything to me unfortunately 😖

zadjii-msft avatar Jan 29 '21 16:01 zadjii-msft

any instructions on how to debug / provide useful information?

ghost avatar Jan 29 '21 17:01 ghost

If it's not too much trouble, we might be able to figure this out by building from source and throwing breakpoints at the top of OpenTerminalHere::_GetPathFromExplorer, in ...src\cascadia\ShellExtension\OpenTerminalHere.cpp. Since this only repros when right clicking in the empty space in explorer, then I'm pretty sure it's due to the code in that function.

/cc @hereafter, because they might have some ideas what's going on here (#8638)

zadjii-msft avatar Jan 29 '21 17:01 zadjii-msft

Note to anybody else debugging the issue: Set the breakpoint after this line, otherwise GetForegroundWindow() returns wrong HWND (of something inside Diagnostics Tools pane in VS) https://github.com/microsoft/terminal/blob/e7d32625befb85e5b40380de20c62172e7275c5e/src/cascadia/ShellExtension/OpenTerminalHere.cpp#L242

Anyways, https://github.com/microsoft/terminal/blob/e7d32625befb85e5b40380de20c62172e7275c5e/src/cascadia/ShellExtension/OpenTerminalHere.cpp#L269 this is the line that fails with error - REGDB_E_CLASSNOTREG, 0x80040154, Class not registered

[Stack Trace]	0x000001a7ee447830 {[External Code], WindowsTerminalShellExt.dll!winrt::hresult_error::originate(const winrt::hresult code, void * message) Line 4588, ...}	unsigned __int64[0x0000001f]
[0]	[External Code]	void*
[1]	WindowsTerminalShellExt.dll!winrt::hresult_error::originate(const winrt::hresult code, void * message) Line 4588	void*
[2]	WindowsTerminalShellExt.dll!winrt::hresult_error::hresult_error(const winrt::hresult code, winrt::take_ownership_from_abi_t __formal) Line 4523	void*
[3]	WindowsTerminalShellExt.dll!winrt::hresult_class_not_registered::hresult_class_not_registered(winrt::take_ownership_from_abi_t __formal) Line 4670	void*
[4]	WindowsTerminalShellExt.dll!winrt::throw_hresult(const winrt::hresult result) Line 4752	void*
[5]	WindowsTerminalShellExt.dll!winrt::check_hresult(const winrt::hresult result) Line 4827	void*
[6]	WindowsTerminalShellExt.dll!winrt::capture<IShellWindows,int (__cdecl*)(winrt::guid const &,void *,unsigned int,winrt::guid const &,void * *) noexcept,winrt::guid const &,void * &,unsigned int &>(int(*)(const winrt::guid &, void *, unsigned int, const winrt::guid &, void * *) noexcept function, const winrt::guid & <args_0>, void * & <args_1>, unsigned int & <args_2>) Line 2452	void*
[7]	WindowsTerminalShellExt.dll!winrt::create_instance<IShellWindows>(const winrt::guid & clsid, unsigned int context, void * outer) Line 6222	void*
[8]	WindowsTerminalShellExt.dll!OpenTerminalHere::_GetPathFromExplorer() Line 269	void*
[9]	WindowsTerminalShellExt.dll!OpenTerminalHere::Invoke(IShellItemArray * psiItemArray, IBindCtx * __formal) Line 126	void*
[10]	[External Code]	void*

nc-x avatar Jan 30 '21 08:01 nc-x

Same issue for me, still not working 😟

ahmedDev20 avatar Jan 30 '21 18:01 ahmedDev20

Same issue +1

wd30x avatar Jan 31 '21 09:01 wd30x

If you'd like to "+1" this feature, the best way to do that is by hitting the 👍 button on this issue

image

That way, you avoid unnecessarily pinging everyone following this thread. Thanks!

zadjii-msft avatar Jan 31 '21 11:01 zadjii-msft

i am not able to repro the issue.

I suspect it is due to the context so could you please change the line to auto shell = create_instance(CLSID_ShellWindows, CLSCTX_ALL); @nc-x

hereafter avatar Jan 31 '21 13:01 hereafter

@hereafter after changing to

auto shell = create_instance<IShellWindows>(CLSID_ShellWindows, CLSCTX_ALL);

it no longer crashes at this line.

it now crashes at L282 - disp.put() https://github.com/microsoft/terminal/blob/e7d32625befb85e5b40380de20c62172e7275c5e/src/cascadia/ShellExtension/OpenTerminalHere.cpp#L280-L298 image However, after clicking on Ignore, the Terminal does open correctly :D

EDIT: If only a single explorer window is open, it works the first time itself. If more than one windows are open, say x number of windows, then it gives the error x-1 times, after which it opens correctly.

nc-x avatar Jan 31 '21 14:01 nc-x

EDIT: looks like we need to clear disp and tmp to nullptr somehow, i am positive that CLSCTX_ALL fixed the issue the warning is just a side-effect for warn of re-using com_ptr

hereafter avatar Jan 31 '21 14:01 hereafter

@nc-x

could you please take the code here

https://github.com/hereafter/terminal/blob/dev/hereafter/context-menu-patch/src/cascadia/ShellExtension/OpenTerminalHere.cpp

image

to see if it works for you now

hereafter avatar Jan 31 '21 14:01 hereafter

Thanks, it works perfectly.

diff --git a/src/cascadia/ShellExtension/OpenTerminalHere.cpp b/src/cascadia/ShellExtension/OpenTerminalHere.cpp
index bd748338..1c2649df 100644
--- a/src/cascadia/ShellExtension/OpenTerminalHere.cpp
+++ b/src/cascadia/ShellExtension/OpenTerminalHere.cpp
@@ -266,7 +266,7 @@ std::wstring OpenTerminalHere::_GetPathFromExplorer() const
         return path;
     }
 
-    auto shell = create_instance<IShellWindows>(CLSID_ShellWindows);
+    auto shell = create_instance<IShellWindows>(CLSID_ShellWindows, CLSCTX_ALL);
     if (shell == nullptr)
     {
         return path;
@@ -285,6 +285,7 @@ std::wstring OpenTerminalHere::_GetPathFromExplorer() const
         com_ptr<IWebBrowserApp> tmp;
         if (FAILED(disp->QueryInterface(tmp.put())))
         {
+            disp = nullptr;
             continue;
         }
 
@@ -293,8 +294,10 @@ std::wstring OpenTerminalHere::_GetPathFromExplorer() const
         if (hwnd == tmpHWND)
         {
             browser = tmp;
+            disp = nullptr;
             break; //found
         }
+        disp = nullptr;
     }
 
     if (browser != nullptr)

I have also set up teamviewer, so in case any debugging is still required, please let me know.

nc-x avatar Jan 31 '21 14:01 nc-x

THANK YOU VERY MUCH

that would be good enough for now I am making a pr to the mess I left

hereafter avatar Jan 31 '21 14:01 hereafter

Wow, good work on the investigation here everyone! Thanks!

zadjii-msft avatar Feb 01 '21 12:02 zadjii-msft

was here to report this issue...how do I get this now?

typedefstructer avatar Feb 01 '21 22:02 typedefstructer