.net 如何对未加载的 VSTO 插件进行故障排除?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4668777/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to troubleshoot a VSTO addin that does not load?
提问by Heinzi
My VSTO Outlook Add-in suddenly stopped working on one customer machine (it does not load, no error message) and I'm stuck with troubleshooting. The machine is Windows 7 x86, Outlook 2007. The add-in is written with Visual Studio 2008 and uses VSTO 2005 with the 2003 PIAs (because we need to support Outlook 2003 as well). It works perfectly fine on other machines.
我的 VSTO Outlook 插件突然停止在一台客户机器上工作(它没有加载,没有错误消息),我被困在故障排除中。机器是Windows 7 x86,Outlook 2007。插件是用Visual Studio 2008编写的,使用VSTO 2005和2003 PIA(因为我们也需要支持Outlook 2003)。它在其他机器上工作得很好。
Here's what I tried to get useful troubleshooting output:
这是我试图获得有用的故障排除输出的内容:
- Add the
VSTO_SUPPRESSDISPLAYALERTSenvironment variable (set to0). - Start Outlook with administrative permissions.
- Look into the event log.
- 添加
VSTO_SUPPRESSDISPLAYALERTS环境变量(设置为0)。 - 使用管理权限启动 Outlook。
- 查看事件日志。
Nothing. The add-in just won't load without giving anyindication of the reason. I've also checked the "usual suspects" (CAS policy, PIAs installed, LoadBehavior in the registry, reinstalling VSTO and the add-in).
没有。加载项不会在没有给出任何原因指示的情况下加载。我还检查了“通常的嫌疑人”(CAS 策略、安装的 PIA、注册表中的 LoadBehavior、重新安装 VSTO 和加载项)。
Some other observations:
其他一些观察:
LoadBehaviorin the registry stays at3.- The add-in shows up as "disabled" in Outlook. Checking its checkbox in "COM add-ins" just does nothing (no error, checkbox is cleared again when entering the form a second time).
- It works perfectly fine on other customer machines, and it worked perfectly fine on this machine. (No, the customer cannot tell me what changed on his machine.)
- I have a
Trace.WriteLinemessage at the very top of my code (first line in theThisAddIn_Startuphandler), which is not reached (I checked with DebugView). Thus, the reason for not loading is not an exception in my add-in but rather a failure of VSTO to load the add-in or of Outlook to load VSTO.
LoadBehavior在注册表中停留在3。- 该加载项在 Outlook 中显示为“已禁用”。在“COM 加载项”中选中它的复选框没有任何作用(没有错误,第二次输入表单时再次清除复选框)。
- 它在其他客户机器上运行得非常好,在这台机器上运行得非常好。(不,客户不能告诉我他的机器上发生了什么变化。)
- 我
Trace.WriteLine在代码的最顶部(ThisAddIn_Startup处理程序中的第一行)有一条消息,但未到达(我使用DebugView进行了检查)。因此,未加载的原因不是我的加载项中的异常,而是 VSTO 加载加载项失败或 Outlook 加载 VSTO 失败。
Instead of more random debugging ("try this...", "try that..."), I'd really like to force Outlook and/or VSTO to tell me what's wrong, i.e. to give me a useful error message instead of just doing nothingwhen trying to enable the add-in. Any ideas?
而不是更多的随机调试(“试试这个……”,“试试那个……”),我真的很想强制 Outlook 和/或 VSTO 告诉我出了什么问题,即给我一条有用的错误消息只是无所事事试图启用加载项时。有任何想法吗?
采纳答案by Gardner
Did you try enabling the add-in again? It won't run after its in the disabled queue. After you re-enable it from the disabled add-in screen, you can then check the box in the COM-AddIn screen to have it load which then should prompt you more detail since you set the VSTO_SUPPRESSDISPLAYALERTSvariable about what may have happened in the first place.
您是否尝试再次启用加载项?它不会在禁用队列中运行。从禁用的加载项屏幕重新启用它后,您可以选中 COM-AddIn 屏幕中的框以加载它,然后应该会提示您更多详细信息,因为您设置了VSTO_SUPPRESSDISPLAYALERTS有关第一个可能发生的情况的变量地方。
回答by Heinzi
Here's a bit more detail on RobertG5's solution (too long for a comment):
这里有更多关于 RobertG5 解决方案的细节(评论太长):
The problem was that the add-in had been hard disabledby Outlook. As I've learned, that's something different than the "usual" not-loading scenario. The key to realizing this was to notice that the add-in did not show up under Inactive Application Add-Ins, but rather under Disabled Application Add-Ins. That makes a difference: In the latter case, just going to the COM-AddIn screen and ticking the check box just does nothing. (I guess a nice message box "You cannot load this add-in because it has been hard-disabled" would be too much to ask... sigh.)
问题是该加载项已被Outlook硬禁用。据我所知,这与“通常的”未加载场景有所不同。实现这一点的关键是注意加载项没有显示在Inactive Application Add-Ins 下,而是在Disabled Application Add-Ins 下。这有区别:在后一种情况下,只需转到 COM-AddIn 屏幕并勾选复选框就什么都不做。(我想一个不错的消息框“您无法加载此加载项,因为它已被硬禁用”会问太多......叹气。)
So, how do I re-enable a hard disabled add-in?
那么,如何重新启用硬禁用加载项?
- In the Managebox, change COM Add-insto Disabled Add-ins, and then click Go.
- Select the add-in and click Enable. Click Close.
- 在“管理”框中,将“ COM 加载项”更改为“禁用加载项”,然后单击“执行”。
- 选择加载项并单击启用。单击关闭。
OK, now the add-in can be loaded again:
好的,现在可以再次加载加载项:
- In the Managebox, change Disabled Add-insto COM Add-ins, and then click Go.
- select the check box next to the disabled add-in. Click OK.
- 在“管理”框中,将“禁用的加载项”更改为“ COM 加载项”,然后单击“执行”。
- 选中已禁用加载项旁边的复选框。单击“确定”。
Reference: http://msdn.microsoft.com/en-us/library/ms268871.aspx
回答by Jeremy Thompson
I know this is old but for various reasons I've recently been troubleshooting Office Add-Ins that dont load.
我知道这是旧的,但由于各种原因,我最近一直在对无法加载的 Office 加载项进行故障排除。
Its chewed up heaps of time so I thought I'd share, so if your add-in wont load or its not visible or etc please try these solutions.
它占用了大量时间,所以我想我会分享,所以如果您的加载项无法加载或不可见等,请尝试这些解决方案。
1). The Add-In is not loaded.
1)。加载项未加载。
Not loaded. A runtime error occurred during the loading of the COM Add-In.
未加载。加载 COM 加载项期间出现运行时错误。


The problem is due to missing .Net framework 3.5 or 4.0.
问题是由于缺少 .Net framework 3.5 或 4.0。
Note: on a x64 I only need .Net 4.0 however on a x86 PC I got the error after installing .Net 4.0. Following this articleI installed .Net 3.5 as well and then it worked on the x86 PC!
注意:在 x64 上我只需要 .Net 4.0 但是在 x86 PC 上我在安装 .Net 4.0 后出现错误。在这篇文章之后,我也安装了 .Net 3.5,然后它可以在 x86 PC 上运行!
2). The Add-In is not loaded.
2)。加载项未加载。
Double check you have spelt the registry keys correctly. Occassionally I type Behaviour but in American spelling is Behavior, so double check "LoadBehavior"
仔细检查您是否正确拼写了注册表项。有时我会输入 Behavior 但在美式拼写中是 Behavior,所以请仔细检查“LoadBehavior”


Also make sure "LoadBehavior" is 3, for a list of values see http://msdn.microsoft.com/en-us/library/vstudio/bb386106.aspx#LoadBehavior
还要确保“LoadBehavior”为 3,有关值的列表,请参阅http://msdn.microsoft.com/en-us/library/vstudio/bb386106.aspx#LoadBehavior
3). The Add-In is not visible.
3)。加载项不可见。
You can make the add-In visible by going to Excel > File > Options > Add-Ins > select the Manage dropdownlist and set it to COM Add-Ins > Click GO. In the COM Add-Ins dialog make sure that Add-In is ticked.
您可以通过转到 Excel > 文件 > 选项 > 加载项 > 选择管理下拉列表并将其设置为 COM 加载项 > 单击 GO,使加载项可见。在 COM 加载项对话框中,确保已勾选加载项。
4). The Add-In was disabled.
4)。插件被禁用。
Alternatively the add-in may be hidden because it has been disabled. You can enable the add-In by going to Excel > File > Options > Add-Ins > select the Manage dropdownlist and set it Disabled and click GO. Select the Add-In that has been disabled and click Enable.
或者,加载项可能被隐藏,因为它已被禁用。您可以通过转到 Excel > 文件 > 选项 > 加载项 > 选择管理下拉列表并将其设置为禁用并单击开始来启用加载项。选择已禁用的加载项,然后单击启用。


5). The ExcelDNA User Defined Formula is not rendering correctly
5)。ExcelDNA 用户定义的公式未正确呈现
Instead of seeing the cell value you see: #NAME?
而不是看到您看到的单元格值:#NAME?
Set the following registry key:
设置以下注册表项:
HKEY_CURRENT_USER\Software\Microsoft\Office.0\Excel\options\OPEN:
With the correct value:
使用正确的值:
/R "C:\Program Files\XYZ\XYZ Addin\ExcelDNA.XYZAddIn.xll"
6). Excel HANGS after showing a messagebox
6). 显示消息框后 Excel 挂起
Turn back on the application settings:
重新打开应用程序设置:
xlApp.ScreenUpdating = true;
xlApp.DisplayAlerts = true;
xlApp.Calculation = XlCalculation.xlCalculationAutomatic;
xlApp.UserControl = true;
xlApp.EnableEvents = true;
7). Further troubleshooting
7)。进一步的故障排除
Enable your VSTO log file by adding the following on your system environment variables:
通过在系统环境变量中添加以下内容来启用 VSTO 日志文件:
NAME: VSTO_LOGALERTS
VALUE: 1
There might be an exception error that is why your add-in is not loading.
可能存在异常错误,这就是您的加载项未加载的原因。
You can check this source for more infoon VSTO logging and alerts, but in essence you change two environment variable values depending on what you need to do:
您可以查看此来源以获取有关 VSTO 日志记录和警报的更多信息,但本质上您可以根据需要更改两个环境变量值:
Displaying VSTO Alert Prompts
To display each error in a message box, set the VSTO_SUPPRESSDISPLAYALERTS variable to 0 (zero). You can suppress the messages by setting the variable to 1 (one).
Logging VSTO Alerts to a Log file
To write the errors to a log file, set the
VSTO_LOGALERTSvariable to 1 (one).Visual Studio Tools for Office creates the log file in the folder that contains the application manifest. The default name is .manifest.log. To stop logging errors, set the variable to 0 (zero).
显示 VSTO 警报提示
要在消息框中显示每个错误,请将 VSTO_SUPPRESSDISPLAYALERTS 变量设置为 0(零)。您可以通过将变量设置为 1(一)来抑制消息。
将 VSTO 警报记录到日志文件
要将错误写入日志文件,请将
VSTO_LOGALERTS变量设置为 1(一)。Visual Studio Tools for Office 在包含应用程序清单的文件夹中创建日志文件。默认名称是 .manifest.log。要停止记录错误,请将变量设置为 0(零)。
回答by Cédric Guillemette
I would suggest using a Microsoft tool to diagnose add-in issues called AddinSpy.
我建议使用 Microsoft 工具来诊断名为AddinSpy 的加载项问题。
回答by realPT
Funny for me, I tried a reboot. Fixed it for me. However, The reason it fixed it for me, is I had a rogue Excel.exe running hidden. The addin was not starting due to this other excel application running (I was migrating an MSAccess application to VSTO), so Access had an automation app open hidden.
对我来说很有趣,我尝试重新启动。为我修好了。但是,它为我修复的原因是我隐藏了一个流氓 Excel.exe。由于此其他 excel 应用程序正在运行(我正在将 MSAccess 应用程序迁移到 VSTO),该插件没有启动,因此 Access 隐藏了一个打开的自动化应用程序。
In short, if your addin is not starting up, quick check for is to just make sure there's no other Excel applications running. This of course only applies when you're trying to get a brand new one installed/up and running.
简而言之,如果您的插件没有启动,快速检查只是确保没有其他 Excel 应用程序在运行。这当然仅适用于您尝试安装/启动并运行全新的。
(I used this link) https://www.add-in-express.com/creating-addins-blog/2012/11/13/wix-installation-vsto-office-addin/
(我使用了这个链接) https://www.add-in-express.com/creating-addins-blog/2012/11/13/wix-installation-vsto-office-addin/
回答by Brian H
There is also another possibility here as to why you are getting no feedback even with the Environment Variables mentioned above being set. I found if you were getting this error after an install (not a previous VSTO that had been working) you should also double check the registry and the "Manifest"entry if you have one.
这里还有另一种可能性,即为什么即使设置了上述环境变量,您也没有收到任何反馈。我发现如果您在安装后收到此错误(不是以前一直在工作的 VSTO),您还应该仔细检查注册表和“清单”条目(如果有)。
While Jeremy Thompson points out the Registry in his Second bullet point he does not show the Manifestentry that could be part of your registry settings. If your Manifest entry is not pointing to the correct path and file it will show up in the Add-Ins listing with an entry of "Not Loaded".
虽然 Jeremy Thompson 在他的第二个要点中指出了注册表,但他没有显示可能是您的注册表设置一部分的清单条目。如果您的清单条目未指向正确的路径和文件,它将显示在加载项列表中,并带有一个条目“未加载”。
Here we see a bad entry that just points to the VSTO file only, no path.

这里我们看到一个错误的条目,它只指向 VSTO 文件,没有路径。

This will cause your AddIn to look like it loaded with errors, but no errors are popping up and appearing for you and making things frustrating. So it will look like this below, notice the location entry below also does not show the path.

这将导致您的 AddIn 看起来像是加载了错误,但没有错误弹出并出现并让您感到沮丧。所以它看起来像下面这样,注意下面的位置条目也没有显示路径。

Correct the entry by putting in the proper path along with the file name and it will fix this.
通过放入正确的路径和文件名来更正条目,它会解决这个问题。
The lack of errors I assume comes from the fact that you were pointing at nothing initially, so it lists the AddIn because it is in the registry, even though there is nothing to load.
我认为没有错误是因为您最初没有指向任何内容,因此它列出了 AddIn,因为它在注册表中,即使没有任何内容可加载。
回答by JasonPlutext
Eventually I coaxed Word to tell me:
最后我哄着 Word 告诉我:
Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateStartupObjectException:
Could not create an instance of startup object blaghblagh --->
System.TypeInitializationException: The type initializer for 'foo' threw an exception. --->
System.IO.FileNotFoundException: Could not load file or assembly 'blah' or one of its dependencies.
The system cannot find the file specified.
After that, thanks to [1], FusLogvw quickly solved the problem for me.
之后,感谢[1],FusLogvw很快就为我解决了问题。
[1] Could not load file or assembly or one of its dependencies

