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

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

Closed
ghost opened this issue Jan 29, 2021 · 34 comments · Fixed by #8977
Closed

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

ghost opened this issue Jan 29, 2021 · 34 comments · Fixed by #8977
Labels
Area-ShellExtension For issues related to the explorer right-click context menu Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@ghost
Copy link

ghost commented Jan 29, 2021

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 ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jan 29, 2021
@LucaBlackDragon
Copy link

LucaBlackDragon commented Jan 29, 2021

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.

@zadjii-msft
Copy link
Member

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

@ghost
Copy link

ghost commented Jan 29, 2021

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 ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jan 29, 2021
@zadjii-msft zadjii-msft added Area-ShellExtension For issues related to the explorer right-click context menu Product-Terminal The new Windows Terminal. labels Jan 29, 2021
@LucaBlackDragon
Copy link

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.

@ghost
Copy link
Author

ghost commented Jan 29, 2021

@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 ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jan 29, 2021
@zadjii-msft
Copy link
Member

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 zadjii-msft added Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Jan 29, 2021
@ghost
Copy link
Author

ghost commented Jan 29, 2021

any instructions on how to debug / provide useful information?

@zadjii-msft
Copy link
Member

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)

@nc-x
Copy link

nc-x commented Jan 30, 2021

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)

auto hwnd = ::GetForegroundWindow();

Anyways,

auto shell = create_instance<IShellWindows>(CLSID_ShellWindows);

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*

@ahmedDev20

This comment has been minimized.

@wd30x

This comment has been minimized.

@zadjii-msft
Copy link
Member

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 zadjii-msft added this to the Terminal v1.7 milestone Jan 31, 2021
@zadjii-msft zadjii-msft added the zStable-Service-Queued-1.12 A floating label that tracks the current Stable version for servicing purposes. label Jan 31, 2021
@hereafter
Copy link
Contributor

hereafter commented Jan 31, 2021

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

@nc-x
Copy link

nc-x commented Jan 31, 2021

@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()

// look for correct explorer window
for (variant.intVal = 0;
shell->Item(variant, disp.put()) == S_OK;
variant.intVal++)
{
com_ptr<IWebBrowserApp> tmp;
if (FAILED(disp->QueryInterface(tmp.put())))
{
continue;
}
HWND tmpHWND = NULL;
hr = tmp->get_HWND(reinterpret_cast<SHANDLE_PTR*>(&tmpHWND));
if (hwnd == tmpHWND)
{
browser = tmp;
break; //found
}
}

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.

@hereafter
Copy link
Contributor

hereafter commented Jan 31, 2021

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
Copy link
Contributor

hereafter commented Jan 31, 2021

@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

@nc-x
Copy link

nc-x commented Jan 31, 2021

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.

@hereafter
Copy link
Contributor

hereafter commented Jan 31, 2021

THANK YOU VERY MUCH

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

@zadjii-msft zadjii-msft added the zPreview-Service-Queued-1.13 A floating label that tracks the current Preview version for servicing purposes. label Feb 1, 2021
@ghost ghost closed this as completed in #8977 Feb 1, 2021
@ghost ghost removed the In-PR This issue has a related PR label Feb 1, 2021
ghost pushed a commit that referenced this issue Feb 1, 2021
Fix a bug brought in with PR: #8638 


see,
#8936 
#8638

* [x] Closes #8936
* [x] CLA signed
* [x] Tests passed


With the help from @nc-x, the issue is reproduced and fixed by this patch.

CLSCTX_IN_PROCESS is not good enough for all cases to create IShellWindows interface.
Put a CLSCTX_ALL fixes the issue.


Another debugging warning dialogs  for reusing not null com_ptr in the loop is fixed too.
(This was shown in debug builds only)
@ghost ghost added the Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. label Feb 1, 2021
@typedefstructer
Copy link

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

@zadjii-msft
Copy link
Member

Right now, we've committed the fix to main. We're working on a couple other hot bugs right now, and should have a servicing release out later this week. Thanks for the patience!

DHowett pushed a commit that referenced this issue Feb 5, 2021
Fix a bug brought in with PR: #8638

see,
#8936
#8638

* [x] Closes #8936
* [x] CLA signed
* [x] Tests passed

With the help from @nc-x, the issue is reproduced and fixed by this patch.

CLSCTX_IN_PROCESS is not good enough for all cases to create IShellWindows interface.
Put a CLSCTX_ALL fixes the issue.

Another debugging warning dialogs  for reusing not null com_ptr in the loop is fixed too.
(This was shown in debug builds only)

(cherry picked from commit e207236)
DHowett pushed a commit that referenced this issue Feb 5, 2021
Fix a bug brought in with PR: #8638

see,
#8936
#8638

* [x] Closes #8936
* [x] CLA signed
* [x] Tests passed

With the help from @nc-x, the issue is reproduced and fixed by this patch.

CLSCTX_IN_PROCESS is not good enough for all cases to create IShellWindows interface.
Put a CLSCTX_ALL fixes the issue.

Another debugging warning dialogs  for reusing not null com_ptr in the loop is fixed too.
(This was shown in debug builds only)

(cherry picked from commit e207236)
@DHowett DHowett removed the zPreview-Service-Queued-1.13 A floating label that tracks the current Preview version for servicing purposes. label Feb 5, 2021
@AlJohri
Copy link

AlJohri commented Feb 10, 2021

hi @zadjii-msft! just wanted to check in to see if this fix was released? I see that the issue is assigned to the v1.7 milestone- should I check back on February 28th?

@tejas-hosamani
Copy link

Maybe a point worth noting - When I use context menu as the OP has shared, it gives me an error but if I right-click on the folder itself and choose Open in Windows Terminal, it does work.

image

image

@DHowett
Copy link
Member

DHowett commented Feb 10, 2021

This is due to be released in a bugfix update to 1.6 this week.

@schlamar
Copy link

But stable 1.5 won't get an update?

@zadjii-msft
Copy link
Member

1.5 won't get an update because the bug wasn't present in 1.5. The support for the context menu in the background of a directory was only added in 1.6. That feature had a bug that would cause this error message for some users. We can patch that bug in 1.6, but we're not going to bring the whole feature down a level (since clearly, it needs more time to bake in Preview).

@schlamar
Copy link

@zadjii-msft I have 1.5.10271.0 installed, there is this entry in the context menu and I'm getting this error. I haven't installed the Preview version.

@zadjii-msft
Copy link
Member

Well, that's certainly not expected. @DHowett we didn't sneak this context menu entry into 1.5, did we?

@schlamar
Copy link

@zadjii-msft
Copy link
Member

Well then this should probably be serviced to 1.5 too. That's what we get for sneaking features into the stable builds.

@arthursoas
Copy link

What is the resolution? I'm still facing this issue, and I downloaded the last version of Terminal

@zadjii-msft
Copy link
Member

@arthursoas Please read the thread. This is fixed in main, and is going to get serviced (read: pushed to the store as an update) to 1.6 (and 1.5) later this week.

@ghost
Copy link

ghost commented Feb 11, 2021

🎉This issue was addressed in #8977, which has now been successfully released as Windows Terminal v1.5.10411.0.:tada:

Handy links:

@ghost
Copy link

ghost commented Feb 11, 2021

🎉This issue was addressed in #8977, which has now been successfully released as Windows Terminal Preview v1.6.10412.0.:tada:

Handy links:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-ShellExtension For issues related to the explorer right-click context menu Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.