0

I am developing a visual studio package which will take the form of an extension for SSMS (SQL Server Management Studio). I want to open SSMS when I run the project in debug mode. When I press run, SSMS opens normally but as soon as I try to connect to a database Visual Studio throws this exeption:

Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe'.

Additional information: A call to PInvoke function 'ObjectExplorer!Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.Service::GetBrowserInfoInterop' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

If I hit 'continue' it will display the same exception a couple more times but eventually it will go away. SSMS runs normally, the item in the Tools menu shows up (photo attached) SSMS print screen

But the problem is that break points are not hit on Visual Studio.

enter image description here

I chose SSMS as the startup program from "Start external program" in the Debug section in project properties. By default it has devenv.exe from the VS15 installation folder. Now, I'm thinking that the problem here is that debugging is available only if the devenv.exe is selected as the external program. Am I right? If so, is there any way to enable debugging?

Community
  • 1
  • 1
Endi Zhupani
  • 736
  • 2
  • 7
  • 22
  • 1
    http://stackoverflow.com/questions/3506796/pinvokestackimbalance-how-can-i-fix-this-or-turn-it-off – Techidiot Sep 20 '16 at 13:02
  • The exception did disappear but I still can't hit the breakpoints. I'd like to be able to set breakpoints and hit them, as I'm still developing the software and without debugging it would be a nightmare. @Techidiot – Endi Zhupani Sep 20 '16 at 13:06
  • I have no experience with this specifically, but I would bet that SSMS runs its plugins in a separate process. Did you try adding a `System.Diagnostics.Debugger.Launch()` in your code and see if you can get the JIT debugger window to allow you to attach? – Dark Falcon Sep 20 '16 at 13:23
  • Never mind, I just needed to rebuild after i turned off PInvokeStackImbalance and copy the dll into the Extensions folder in SSMS installation folder – Endi Zhupani Sep 20 '16 at 13:42

1 Answers1

0

I managed to solve this. First I need to turn off PInvokeStackImbalance

  1. CTRL + ALT + E
  2. Under "Managed Debugging Assistants" uncheck PInvokeStackImbalance.

And then just rebuild and copy the new dll's in the Extensions folder inside the SSMS installation folder

Endi Zhupani
  • 736
  • 2
  • 7
  • 22