开发者

Word Interop compile time error

开发者 https://www.devze.com 2022-12-31 17:13 出处:网络
I am getting the following error when referencing the assembly Microsoft.Office.Interop.Word in my asp.net application.

I am getting the following error when referencing the assembly Microsoft.Office.Interop.Word in my asp.net application.

The type 'Microsoft开发者_如何学Go.Office.Interop.Word.ApplicationClass' exists in both

C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Word\11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll

and

C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Word\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll

Previously, I was getting the error but the 12.0.0.0 was in the PIA directory under Visual Studio, but the error message was the same, except pointing to a different path. Since then, I copied the dll to the GAC, but with the same error.

I thought that .Net was supposed to take care of this. Can anyone give me some help?

BTW, I am doing this using Visual Studio .Net 2008


This is from the previous answer, but with relevant information included, in case the reference dies of link-rot:


Problems with Primary Interop Assembly Versioning: Using the .config file and the assembly binding redirection, I've finally been able to get rid of the originally reported exception. I've created a .config file containing the information about the assembly binding redirections. The .config was then copied to a directory containing the hosting application binaries. Now both the old and the plugins coexist and work correctly without a need to use the Marshal.CreateWrapperOfType method when casting a COM component so it seems there is a workaround and I didn't even have to make changes to the GAC. There are still some issues to be addressed but for now it seems there is a plausable solution.

<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>

[there is more discussion of the underlying cause, other possible-but-awkward solutions at the link]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号