开发者

How do you debug a visual studio add-in that throws an exception during loading?

I'm working on an add-in for Visual Studio 2005 in C#, and while everything works if I launch it from the debugger, actually installing it (adding the .addin and .dll to the add-ins directory) results in it not working. When Visual Studio loads it, I get the error "The Add-in "MyAddin" failed to load or caused an exception." With Error Message: Unspecified error, with error number: 80004005, and then offers me the ability to disable it.

From here, I can't figure out how to debug that load process in order to figure out what's开发者_运维知识库 going on. I can't seem to attach to the dll before it's loaded, or specifically launch the dll in a fashion that causes it to load in the same fashion. I also can't attach when the error message is up.

How on earth do I do this?

Edit: I'm starting to believe this isn't a problem with my code so much as the .addin file. Given that I can't break the code in the constructor, and the MyAddin - For Testing.addin works, perhaps it is a larger issue with the generated MyAddin.addin file.


Add the line below at the beginning of your code. This will prompt you if you'd like to open up a VS window to debug (see MSDN). Then you can step through your code as needed.

Debugger.Break();

There is a benefit of using this method over "Attach to Process" in that you won't have to worry about attaching to the process each time and before the exception occurs.


The easiest way, which might not trigger the same exception:

  • Disable the load on startup.
  • Start 2 Visual Studio instances.
  • Use Tools -> Attach to Process to attach it as a debugger to the other instance.
  • Optionally also set Debug -> Exceptions to break on all CLR exceptions.
  • Load the addin in the debuggee


Maybe it requires a native side break point on appearances of 80004005 in devenv.exe. This usually requires you are familiar with WinDbg or so on.

If your company has a support contract with Microsoft, open a support case via http://support.microsoft.com to involve the experts.


After sleeping on it, I came back fresh and re-looked at everything. Turns out the generated .Addin file had a broken reference, and so was trying to load a non-existent file. After fixing the reference, everything works great (including 30 Break()s being called during visual studio start-up... but at least I know that was working.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜