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

Errors require STA #159

Closed
miloush opened this issue Jan 19, 2020 · 13 comments
Closed

Errors require STA #159

miloush opened this issue Jan 19, 2020 · 13 comments
Assignees
Labels
Milestone

Comments

@miloush
Copy link
Contributor

miloush commented Jan 19, 2020

Could it be possible to print the exception to the debug output before trying to show the error dialog?

Snooping application.
Starting snoop UI...
System.InvalidOperationException: The calling thread must be STA, because many UI components require this.
   at System.Windows.Input.InputManager..ctor()
   at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
   at System.Windows.Input.KeyboardNavigation..ctor()
   at System.Windows.FrameworkElement.FrameworkServices..ctor()
   at System.Windows.FrameworkElement.EnsureFrameworkServices()
   at System.Windows.FrameworkElement..ctor()
   at System.Windows.Controls.Control..ctor()
   at System.Windows.Window..ctor()
   at Snoop.ErrorDialog..ctor() in C:\projects\snoopwpf\Snoop.Core\ErrorDialog.xaml.cs:line 16
   at Snoop.ErrorDialog.ShowDialog(Exception exception, String title, String caption, Boolean exceptionAlreadyHandled) in C:\projects\snoopwpf\Snoop.Core\ErrorDialog.xaml.cs:line 48
   at Snoop.Infrastructure.SnoopManager.GoBabyGoForCurrentAppDomain(TransientSettingsData settingsData) in C:\projects\snoopwpf\Snoop.Core\Infrastructure\SnoopManager.cs:line 137
   at Snoop.Infrastructure.SnoopManager.StartSnoopInstance(String settingsFile) in C:\projects\snoopwpf\Snoop.Core\Infrastructure\SnoopManager.cs:line 97
   at Snoop.Infrastructure.SnoopManager.StartSnoop(String settingsFile) in C:\projects\snoopwpf\Snoop.Core\Infrastructure\SnoopManager.cs:line 21
@batzen
Copy link
Collaborator

batzen commented Jan 20, 2020

Will add the error to the debug output.
Any chance you could provide a repro application for this? It's quite strange that snoop tries to attach to an application that does not seem to be a WPF application.

@batzen batzen self-assigned this Jan 20, 2020
@batzen batzen added the bug label Jan 20, 2020
@batzen batzen added this to the 3.0 milestone Jan 20, 2020
@miloush
Copy link
Contributor Author

miloush commented Jan 20, 2020

This is a WPF element hosted in ElementHost inside System.Windows.Forms.UserControl hosted in an ActiveX container, i.e. VSTO add-in.

Snoop 2 showed a message box instead (maybe that's an alternative for when STA is not available), saying Can't find a current application or a PresentationSource root visual!.

Probably a separate issue, but if that is still the error it is trying to show, can we get at least the tree and properties up without a PresentationSource? The Visual Studio visualizer can do that even in this case (not the Live Tree though).

@batzen
Copy link
Collaborator

batzen commented Jan 25, 2020

Could you try the latest build from appveyor and see if your issue is really fixed?
There should be no error dialog if only one app domain fails.

You can grab the latest source build from https://ci.appveyor.com/project/batzen/snoopwpf/branch/develop/artifacts

@miloush
Copy link
Contributor Author

miloush commented Jan 25, 2020

Okay, so I confirm that if I choose to not snoop multiple domains, I get an error dialog now (with the error as expected above).

If I choose to debug multiple domains, I get the new output and a new exception I believe:

Starting snoop UI...
Could not snoop a specific app domain with friendly name of "DefaultDomain" in multiple app domain mode.
System.InvalidOperationException: The calling thread must be STA, because many UI components require this.
   at System.Windows.Input.InputManager..ctor()
   at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
   at System.Windows.Input.KeyboardNavigation..ctor()
   at System.Windows.FrameworkElement.FrameworkServices..ctor()
   at System.Windows.FrameworkElement.EnsureFrameworkServices()
   at System.Windows.FrameworkElement..ctor()
   at System.Windows.Controls.Control..ctor()
   at System.Windows.Window..ctor()
   at Snoop.Windows.SnoopBaseWindow..ctor() in C:\projects\snoopwpf\Snoop.Core\Windows\SnoopBaseWindow.cs:line 13
   at Snoop.SnoopUI..ctor() in C:\projects\snoopwpf\Snoop.Core\SnoopUI.xaml.cs:line 52
   at Snoop.Infrastructure.SnoopManager.<>c.<GetInstanceCreator>b__3_0() in C:\projects\snoopwpf\Snoop.Core\Infrastructure\SnoopManager.cs:line 155
   at Snoop.Infrastructure.SnoopManager.SnoopApplication(TransientSettingsData settingsData, Func`1 instanceCreator) in C:\projects\snoopwpf\Snoop.Core\Infrastructure\SnoopManager.cs:line 177
   at Snoop.Infrastructure.SnoopManager.GoBabyGoForCurrentAppDomain(TransientSettingsData settingsData) in C:\projects\snoopwpf\Snoop.Core\Infrastructure\SnoopManager.cs:line 130
'WINWORD.EXE' (CLR v4.0.30319: MyAddin.vsto|vstolocal): Loaded 'C:\Users\Myself\AppData\Local\assembly\dl3\POJM97RW.QQ0\B0ROJTNR.DQQ\d21304c4\005419d9_5ed3d501\Snoop.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
System.InvalidCastException: Unable to cast transparent proxy to type 'Snoop.Infrastructure.SnoopManager'.
   at Snoop.Infrastructure.SnoopManager.StartSnoopInstance(String settingsFile) in C:\projects\snoopwpf\Snoop.Core\Infrastructure\SnoopManager.cs:line 97
   at Snoop.Infrastructure.SnoopManager.StartSnoop(String settingsFile) in C:\projects\snoopwpf\Snoop.Core\Infrastructure\SnoopManager.cs:line 22

@miloush
Copy link
Contributor Author

miloush commented Jan 25, 2020

The element I am trying to snoop is in MyAddin.vsto|vstolocal AppDomain by the way, i.e. not DefaultDomain. I wonder if rather than default or all domains, I could pick which AppDomain I want to snoop.

@batzen
Copy link
Collaborator

batzen commented Jan 25, 2020

I added more error handling and more logging. Could you give it another try?
If you could provide a repro it would be easier to fix this ;-)

@batzen batzen reopened this Jan 25, 2020
@miloush
Copy link
Contributor Author

miloush commented Jan 25, 2020

Indeed, got the message box in both cases now!

@miloush miloush closed this as completed Jan 25, 2020
@batzen
Copy link
Collaborator

batzen commented Jan 25, 2020

But were you able to see your elements?
Snoop should be able to work in the case you described.

@miloush
Copy link
Contributor Author

miloush commented Jan 25, 2020

No. I have a repro but it's basically same as in #116. I am running x64 Office though, could that make a difference?

@batzen
Copy link
Collaborator

batzen commented Jan 25, 2020

You are right.
I broke the feature completely.
Will investigate and fix it.

@batzen batzen reopened this Jan 25, 2020
@batzen
Copy link
Collaborator

batzen commented Jan 25, 2020

After some investigation it seems as if Microsoft changed something on their side which currently blocks Snoop from working correctly.
The code i wrote for cross app domain to work made some assumptions which are not always true.
So it's not really Microsofts fault but mine because i didn't think about every possible way someone could create an app domain.
It will take me a few iterations to get it working correctly.
Will mention you here if i think that it's fixed.

batzen added a commit that referenced this issue Feb 2, 2020
@batzen
Copy link
Collaborator

batzen commented Feb 2, 2020

@miloush This should work now. At least it works on my machine. ;-)
Could you give it another try?

@miloush
Copy link
Contributor Author

miloush commented Feb 2, 2020

@batzen it does indeed, thank you very much!

@batzen batzen closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants