Word VSTO 4.0 插件无法加载:无法加载文件或程序集

Posted

技术标签:

【中文标题】Word VSTO 4.0 插件无法加载:无法加载文件或程序集【英文标题】:Word VSTO 4.0 Addin fails to load: Could not load file or assembly 【发布时间】:2015-07-13 05:26:29 【问题描述】:

简而言之,我创建了一个 Word VSTO 插件,它可以在多台机器上完美运行,但无法仅在一台机器上加载。我不知道问题出在程序集名称上,还是缺少 DLL。

具体操作方法及错误信息如下:

1- IDE:Microsoft Visual Studio 社区 2013。

2- 安装的 Office 版本:2010 用于所有机器

3- 使用的 .NET 框架:4.0。

4- 目标机器已安装文件 vstor_redist.exe。

5- VSTO 文件的安装方式是将 VSTO 复制到程序文件中,然后运行它。这适用于所有机器,即使是那些无法加载插件的机器。

6- 插件有一个功能区控件。不知道对这件事有没有影响。

7- 开发机:windows 7 64bit

8- 测试机器:windows 7 64bit。 (即使是加载插件失败的那个)

9- 仅为一台机器加载程序集时收到的错误消息是:

Could not load file or assembly 'IDMSWord2010AddinProject, Version=4.3.0.0, Culture=neutral, PublicKeyToken=83105d2b5774c812' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)


************** Exception Text **************
System.IO.FileLoadException: Could not load file or assembly 'IDMSWord2010AddinProject, Version=4.3.0.0, Culture=neutral, PublicKeyToken=83105d2b5774c812' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
File name: 'IDMSWord2010AddinProject, Version=4.3.0.0, Culture=neutral, PublicKeyToken=83105d2b5774c812'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.CreateEntryPoint(String entryPointTypeName)
   at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.Microsoft.VisualStudio.Tools.Office.Runtime.Interop.IExecuteCustomization2.LoadEntryPoints(IntPtr serviceProvider)




************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1026 (RTMGDR.030319-1000)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.Runtime
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.50903.0
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.Runtime/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.Runtime.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.233 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1026 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Hosting
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.50903.0
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Hosting/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Hosting.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Runtime
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.50903.0
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Runtime/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Runtime.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1026 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1015 (RTMGDR.030319-1000)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Deployment
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1029 (RTMGDR.030319-1000)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Deployment/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.ServerDocument
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.50903.0
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.ServerDocument/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1002 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1001 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Xml.Linq
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll
----------------------------------------
Microsoft.Office.Tools
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.50903.0
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.Office.Tools/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.Office.Tools.dll
----------------------------------------
Microsoft.Office.Tools.Word.Implementation
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.50903.0
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.Office.Tools.Word.Implementation/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.Office.Tools.Word.Implementation.dll
----------------------------------------
Microsoft.Office.Tools.Common.Implementation
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.50903.0
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.Office.Tools.Common.Implementation/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.Office.Tools.Common.Implementation.dll
----------------------------------------
Microsoft.Office.Tools.Common
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.50903.0
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.Office.Tools.Common/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.Office.Tools.Common.dll
----------------------------------------
Microsoft.Office.Tools.Word
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.50903.0
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.Office.Tools.Word/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.Office.Tools.Word.dll
----------------------------------------

非常感谢任何帮助或建议。

此致

【问题讨论】:

【参考方案1】:

我发现了问题。 Office 是 64 位的,插件是 32 位的。我完全忘记检查了。刚编译成64位就解决了。

【讨论】:

【参考方案2】:

这台机器上可能有不同版本的程序集。

您是否尝试过以下方法:

在 Visual Studio 中,转到指向程序集的引用。将“特定版本”属性设置为 false。

然后将应用部署到机器上,看看能不能用。

如果这不起作用,我会尝试在问题机器上重新安装插件的正确版本,并比较相关程序集的程序集版本从可以工作的机器与不能工作的机器的差异。

【讨论】:

原来office是64位的,插件是32位的。重新编译成64位,再试一次,一切正常。

以上是关于Word VSTO 4.0 插件无法加载:无法加载文件或程序集的主要内容,如果未能解决你的问题,请参考以下文章

MS Office Word VSTO“按需加载”

VSTO Word 加载项:内容控制嵌套

如何在 C# VSTO Word 加载项中在页码旁边设置页眉和页脚文本?

深入理解vsto,开发word插件的利器

outlook2007,开发的vsto插件,安装到客户机提示:未加载。加载COM加载项时出现运行错误

VSTO Word 加载项 - 在所选文本周围插入内容控件