[英]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. 我正在使用C#开发Visual Studio 2005的加载项,并且如果从调试器启动它,一切都会正常运行,但实际上安装它(将.addin和.dll添加到加载项目录中)不会工作。 When Visual Studio loads it, I get the error "The Add-in "MyAddin" failed to load or caused an exception."
当Visual Studio加载它时,出现错误“加载项“ MyAddin”加载失败或导致异常。” With Error Message: Unspecified error, with error number: 80004005, and then offers me the ability to disable it.
使用错误消息:未指定的错误,错误号:80004005,然后为我提供禁用它的能力。
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.
在加载dll之前,我似乎无法将其附加到该dll上,也无法以导致其以相同方式加载的方式专门启动该dll。 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. 编辑:我开始相信这与我的代码一样不是.addin文件的问题。 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.
鉴于我无法破坏构造函数中的代码,并且MyAddin-Testing.addin有效,因此生成的MyAddin.addin文件可能是一个更大的问题。
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 ).
这将提示您是否要打开VS窗口进行调试(请参见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: 最简单的方法,可能不会触发相同的异常:
Maybe it requires a native side break point on appearances of 80004005 in devenv.exe. 也许需要在devenv.exe中出现80004005的本地断点。 This usually requires you are familiar with WinDbg or so on.
这通常需要您熟悉WinDbg等。
If your company has a support contract with Microsoft, open a support case via http://support.microsoft.com to involve the experts. 如果您的公司与Microsoft有支持合同,请通过http://support.microsoft.com打开支持案例,以让专家参与。
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.
原来,生成的.Addin文件的引用已损坏,因此试图加载不存在的文件。 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.)
修复参考之后,一切工作正常(包括在Visual Studio启动期间调用了30个Break()……但至少我知道这是可行的。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.