By wirecad in VSTA Tech Discussions
I notice some odd behaviour in the VSTA IDE when debugging. If an exception is encountered outside of a try/catch block the code falls through the block into some unknown state. No feedback is given and debugging must be stopped and the host app restarted to rehook the events. Any ideas?
Thanks for your help
By wirecad in VSTA Tech Discussions
I am debugging out of process and with proxies that are, as yet, a work in progress.
wirecad,
Thanks for the additional info. I'm not observing the same behavior with the ShapeAppMacroRecordingCSharp sample, can you reproduce this behavior with this sample?
To force the macro add-in to crash during debugging, I'm starting the host through Visual Studio, launching the IDE and adding code to the start up method which will not cause a crash if there is a document open. I set a break point (indicated below), start debugging, hit the breakpoint and close the document at the break point, then resume debugging to force a crash. At the line that causes the crash I get a Visual Studio warning that that the NullReferenceException was unhandled by user code, I hit F5 to continue, get a Assert failed (from VstaRunTimeIntegration.LoadAddIn), and I choose to ignore. The rest of the macro method does not execute and the debugger is left in debug mode but can be paused or stopped without any issues and then restarted normally. The host is not frozen during this- it can still be manipulated.
To clean up this behavior, I added a check in the LoadMacros method and if the macroAddIn returned by the LoadAddIn method was null I stopped the debugger. I was not able to achieve a state where no feedback was giveen and the debugger must be stopped and the host app restarted to rehook events (although I wasn't hooking into any events).
If you can't reproduce this error with the ShapeAppMacroRecrodingCSharp sample I would suggest finding the differences between your implementation and the sample in handling the macro add-in (debugging, loading, unloading).
I hope this helps, if you are still stuck please let me know.
Thanks,
-Melody
Macro project:
private voidAppAddIn_Startup(object sender, EventArgs e)
{
try
{
this.NewDocument();
}
catch(Exception ex)
{
System.Windows.Forms.MessageBox.Show("Exception:" + ex.Message);
}
//causes crash if no docucment open
this.ActiveDrawing.Shapes.Add(this.AvailableShapes[3].Clone()); //set break point here and close doc.
this.NewDocument();
this.ActiveDrawing.Shapes.Add(this.AvailableShapes[2].Clone());
}
Updated LoadMacros method to stop the debugger if it crashes:
private void LoadMacros(AddInProcess externalProcess)
{
if (File.Exists(VstaRuntimeIntegration.MacroAddInPath))
{
this.macroAddIn= LoadAddIn(
VstaRuntimeIntegration.MacroAddInPath,
VstaRuntimeIntegration.MacrosStartUpClass,
externalProcess);
//ADDED FORFORUM QUESTION
//if themacro didn't run properly
if (this.macroAddIn == null)
{
//stopthe debugger
this.application.VstaDesignTimeIntegration.StopDebugging(false);
}
// Close theMacro Manager
if (this.application.MacroManager != null)
{
this.application.MacroManager.CloseThreadSafe();
}
}
}