2010-05-24 115 views
1

在我的asp.net應用程序中引用程序集Microsoft.Office.Interop.Word時出現以下錯誤。Word Interop編譯時錯誤

類型 '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是在PIA目錄下的Visual Studio,但錯誤消息是相同的,除了指向一個不同的路徑。從那以後,我將dll複製到了GAC,但是出現了同樣的錯誤。

我以爲.Net應該照顧這個。任何人都可以給我一些幫助嗎?

BTW,我做這個使用Visual Studio .NET 2008

回答

0

這是從previous answer,但相關的信息包括,如果鏈路腐爛的參考模:


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> 

[有潛在原因的詳細討論,在鏈路其他可能的但很彆扭的解決方案]