Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

VsShellUtilities.LaunchDebugger throws Exception: "Operation is not valid due to the current state of the object."

$
0
0

We are extending Visual Studio 2010 Isolated Shell.

We are using it as an IDE for our own application. We have our own project, which has its own hierarchy, and can be build to a binary. ([Project Name].ibs).

We can run a process, our own project, and debug it in our VS extension. We do that by using our own UI there, and just using VS's Debugger so Visual Studio would seem like it is in debug mode.

We do that by Calling:

projectConfig.DebugLaunch((uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_Silent);

This is its implementation:

 /// <summary>
        /// Called by the vs shell to start debugging (managed or unmanaged).
        /// Override this method to support other debug engines.
        /// </summary>
        /// <param name="grfLaunch">A flag that determines the conditions under which to start the debugger. For valid grfLaunch values, see __VSDBGLAUNCHFLAGS</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code</returns>
        public virtual int DebugLaunch(uint grfLaunch)
        {
            CCITracing.TraceCall();

            try
            {
                VsDebugTargetInfo info = new VsDebugTargetInfo();
                info.cbSize = (uint)Marshal.SizeOf(info);
                info.dlo =  Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

                var location = System.Reflection.Assembly.GetExecutingAssembly().Location;
                var packagePath = Path.GetDirectoryName(location);
                var debuggerDummyExecutable = Path.Combine(packagePath, "DummyDebuggerConsole.exe");
                info.bstrExe = debuggerDummyExecutable;

                string property = GetConfigurationProperty("WorkingDirectory", false);
                if (string.IsNullOrEmpty(property))
                {
                    info.bstrCurDir = Path.GetDirectoryName(info.bstrExe);
                }
                else
                {
                    info.bstrCurDir = property;
                }

                property = Path.GetFileNameWithoutExtension(((iBProjectNode)ProjectMgr).ProjectFileName);//GetConfigurationProperty("CmdArgs", false);
                if (!string.IsNullOrEmpty(property))
                {
                    info.bstrArg = property;
                }

                property = GetConfigurationProperty("RemoteDebugMachine", false);
                if (property != null && property.Length > 0)
                {
                    info.bstrRemoteMachine = property;
                }

                info.fSendStdoutToOutputWindow = 0;

                property = GetConfigurationProperty("EnableUnmanagedDebugging", false);
                //info.clsidCustom = new Guid("{D951924A-4999-42a0-9217-1EB5233D1D5A}");

                //info.clsidCustom = new Guid("{3B476D35-A401-11D2-AAD4-00C04F990171}");

                info.clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine;

                info.grfLaunch = grfLaunch;

                VsShellUtilities.LaunchDebugger(this.project.Site, info);
                // 18/05/2014 Magali: StartDebug in ibolt package - projectNode.
                if (ProjectMgr != null)
                {
                    //This is where we call our own process
                    if (!((iBProjectNode)ProjectMgr).ProjAttachToPorjectMode)
                        ((iBProjectNode)ProjectMgr).DebugProject();
                    else  //Here we call our "Attach to Project"
                        ((iBProjectNode)ProjectMgr).AttachToProject();
                }
            }
            catch (Exception e)
            {
                // In case of Attach2ProjectProcess - initialize the flag....
                if (!((iBProjectNode)ProjectMgr).ProjAttachToPorjectMode)
                {
                    ((iBProjectNode)ProjectMgr).InitializeAttachTpProjectIndication();
                    iBMessageBox.ErrorMessage(iBResource.AttachToProject_CancellError);
                }
                else
                    iBMessageBox.ErrorMessage(iBResource.DebugProject_CancellError);

                Trace.WriteLine("Exception : " + e.Message);
                iBLog.AddToLogger(LogLevels.Error, "DebugLaunch ProjectConfig module - process was cancelled due to unexcpected error.");
                return Marshal.GetHRForException(e);
            }

            return VSConstants.S_OK;
        }

This following scenario throws the exception from:

VsShellUtilities.LaunchDebugger(this.project.Site, info);

1. Attach to running process.

==> Succeeds

2. Close solution.

3. Reopen recent solution.

4. Attach to running process.

==> Exception "Operation is not valid due to the current state of the object." occurs

In addition I might add that this following code:

 var serviceProvider = this.project.Site;
                IVsDebugger service = serviceProvider.GetService(typeof(IVsDebugger)) as IVsDebugger;

return null.

Any ideas??

Thanks, 

Shlomi



Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>