在我的asp.net应用程序中引用程序集Microsoft.Office.Interop.Word时,我得到了以下错误。
类型'Microsoft.Office.Interop.Word.ApplicationClass‘同时存在于
C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Word\11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll和
C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Word\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll以前,我得到了错误,但12.0.0.0在Visual Studio下的PIA目录中,但错误消息是相同的,只是指向了不同的路径。从那时起,我将dll复制到GAC,但出现了相同的错误。
我以为.Net应该处理好这件事。有人能帮我一下吗?
顺便说一句,我正在使用Visual Studio .Net 2008来做这件事
发布于 2011-10-25 21:33:25
这是来自previous answer的,但包含相关信息,以防链接-rot的引用死亡:
Problems with Primary Interop Assembly Versioning:使用.config文件和程序集绑定重定向,我终于能够摆脱最初报告的异常。我已经创建了一个.config文件,其中包含有关程序集绑定重定向的信息。然后将.config复制到包含宿主应用程序二进制文件的目录中。现在,旧的插件和插件共存并正常工作,在转换COM组件时不需要使用Marshal.CreateWrapperOfType方法,所以似乎有了解决办法,我甚至不需要对GAC进行更改。仍然有一些问题需要解决,但就目前而言,似乎有一个合理的解决方案。
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MyCompany.Assembly1.Interop"
publicKeyToken="25578904345626a0"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="1.0.1.0"/>
<codeBase version="1.0.1.0"
href="F:\MyApp\bin\Primary Interop Assemblies\MyCompany.Assembl1.Interop.dll"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MyCompany.Assembly2.Interop"
publicKeyToken="25578904345626a0"
culture="neutral" />
<bindingRedirect oldVersion="9.0.0.0"
newVersion="9.0.1.0"/>
<codeBase version="9.0.1.0"
href="F:\MyApp\bin\Primary Interop Assemblies\MyCompany.Assembly2.Interop.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>有更多关于潜在原因的讨论,以及其他可能但笨拙的解决方案
https://stackoverflow.com/questions/2900764
复制相似问题