I have written an Add-in that modifies a (C++, most likely, but could be dot net containing c++) solution.
The Add-in seems to function successfully.
Occasionally , after saving, after even building successfully the solution modified with the Add-in, VisualStudio crashes. It also crashes if i don't save, it crashes if I try to close without saving. Only... Not every time.
The code, after determining that it doesn't need certain projects in the solution, tries to remove them, http://msdn.microsoft.com/en-us/library/envdte._solution.remove(v=vs.100).aspx - in a try-catch - and the removal is successful.
Like I said, I can save, and afterwards, the solution saves and builds properly...
The only problem is, when I try to close the solution, or Visual Studio, it crashes - badly. It may also crash after the AddIn is complete, sometime later... undetermined.
To troubleshoot, I eventually added
try
{
solution.Close(false);
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}
And I got an error:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I don't want to close the solution through code, I just don't want Visual Studio to crash.
Right now, I have replaced the solution.Remove(projectToRemove)
with a MessageBox - and my code is happy - and unable to perform its work.
Thank you for any suggestion.
The answer - unsatisfactory as it is: my code is under source control - I have VisualHg - and after the code completes - after it returns from the AddIn - VisualHg is the one that throws an exception.
It is as far as I got - and fixed the problem by giving up - my AddIn eventually tells the user what projects he should remove - but will stop shy of removing them itself.
Perhaps one day...