Groups | Blog | Home
all groups > visual studio .net ide > june 2004 >

visual studio .net ide : VS crash during addin uninstalling


Szymon Madejczyk
6/22/2004 5:25:57 PM
Hello,

I encountered strange problem. When following code is compiled in Debug it works
ok. However when I compile it in Release. During uninstal VS .net 2003 display
crash warning. What is more no exception is thrown.
BTW addins are removed properly.

Someone has idea what I do wrong.

thanks
Szymek

using System;
using System.Collections;
using System.Diagnostics;
using System.IO;

using EnvDTE;
using Microsoft.Office.Core;

namespace AddinRemover
{
public sealed class Remover
{
private Remover()
{
} // private Cleaner()

private const string VS_71_PROG_ID = "VisualStudio.DTE.7.1";
private const string VS_70_PROG_ID = "VisualStudio.DTE.7";
private const string ADDIN_NAME_COMMON_PART = "MyAddIn";
private const string CMD_BAR_NAME = "My";
private const string ADDIN_NAME = "My";

private static void RemoveAddin(string progId)
{
Type vsType = Type.GetTypeFromProgID(progId);
if (vsType != null)
{
object dteObj = Activator.CreateInstance(vsType);
if (dteObj != null)
{
DTE dte = (DTE)dteObj;
try
{
RemoveCommands(dte);
}
catch(Exception e)
{
Exception exp = e;
}
//dte.Quit();
dte = null;
GC.Collect();
}
}
}

private static void RemoveCommands(DTE dte)
{
Commands cmds = dte.Commands;
_CommandBars commandBars = dte.CommandBars;

try
{
CommandBar toolCommandBar = (CommandBar)commandBars["Tools"];
CommandBarControls ctrls = toolCommandBar.Controls;
IEnumerator en = ctrls.GetEnumerator();
while(en.MoveNext())
{
CommandBarControl ctrl = (CommandBarControl)en.Current;
if (CMD_BAR_NAME == ctrl.Caption)
{
ctrl.Delete(false);
}
}
}
catch(Exception /*e*/)
{
//TODO: logging
}

foreach(Command cmdDel in cmds)
{
if (cmdDel != null && cmdDel.Name != null &&
cmdDel.Name.IndexOf(ADDIN_NAME_COMMON_PART) >= 0)
{
try
{
cmdDel.Delete ( ) ;
}
catch(Exception /*e*/)
{
//TODO: logging
}
}
}

try
{
CommandBar cmdBar = (CommandBar)commandBars[CMD_BAR_NAME];
cmds.RemoveCommandBar(cmdBar);
}
catch(Exception /*e*/)
{
//TODO: logging
}
}

public static void Main(string[] args)
{
try
{
Remover.RemoveAddin(VS_70_PROG_ID);
}
catch(Exception /*e*/)
{
//TODO: logging
}

try
{
Remover.RemoveAddin(VS_71_PROG_ID);
}
catch(Exception /*e*/)
{
//TODO: logging
}
}
}
Carlos J. Quintero [MVP]
6/23/2004 9:56:49 AM
Some ideas:

1) Try to get the exception message. It seems that you are catching and
silencing the exceptions. Use MessageBoxes.

2) If that fails, try to trim your code until you find the culprit. FOr
example, you are doing 3 things: removing controls from command bar,
removing commandbar and removing commands. Surely only one of the 3 is
causing the problem... so try to isolate which one executing only one in
each test.

--

Carlos J. Quintero (Visual Developer - .NET MVP)

FAQs, Knowledge Base, Files, Docs, Articles, Utilities, etc. for .NET
addins:
http://groups.yahoo.com/group/vsnetaddin/ (free join)



"Szymon Madejczyk" <smad@parasoft.com.pl> escribió en el mensaje
news:cb9j7g$5uf$1@nemesis.news.tpi.pl...
[quoted text, click to view]

AddThis Social Bookmark Button