简体   繁体   English

如何调试在加载过程中引发异常的Visual Studio加载项?

[英]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: 最简单的方法,可能不会触发相同的异常:

  • Disable the load on startup. 在启动时禁用负载。
  • Start 2 Visual Studio instances. 启动2个Visual Studio实例。
  • 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. 也可以选择将Debug-> Exceptions设置为在所有CLR异常时中断。
  • Load the addin in the debuggee 将插件加载到调试对象中

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.

相关问题 Visual Studio加载项:如何知道解决方案何时完成加载 - Visual Studio Add-In: How do I know when a solution has finished loading 如何在Visual Studio加载项中获取中断/异常的当前行号? - How to get the current line number at break/exception in Visual Studio add-in? Visual Studio 2017需要在调试期间异常后重新启动 - Visual Studio 2017 requires restart after exception during debug Visual Studio和加载项卸载 - Visual Studio and add-in unloading 如何在Visual Studio 2005加载项中查找并打开文件? - How do I find and open a file in a Visual Studio 2005 add-in? 如何在Visual Studio加载项中获取文件的项目名称? - How to get project name of file in visual studio add-in? 如何在Visual Studio编辑器中编写加载项以更改文本颜色? - How to write an add-in to change text color in Visual Studio editor? 制作Visual Studio外接程序时如何实现IVsStatusbar - How to implement IVsStatusbar when making a Visual Studio Add-In 如何在外接代码中扩展Visual Studio变量? - How to expand Visual Studio variables in the add-in code? 如何从Visual Studio加载项获取项目目录 - How to get the project directory from a Visual Studio Add-in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM