Could not load assembly . . Interop.Word Version 14.0.0.0

我怕爱的太早我们不能终老 提交于 2019-12-24 03:47:08

问题


I have a WinForms application written in C# which auto generates letters in Word. The application works fine with client machines that have Office 2010 installed, but not with those machines with Office 2007 installed, when instead I get the following error message -

could not load file or assembly 'Microsoft.Office.Interop.Word version=14.0.0

I suspect I need to Add a Reference to an older version of Interop.Word e.g. version=12, but there is no such option in the list of references available to be via Visual Studio.

Am I right about needing an older reference and if so where can I locate this?

Or if there is something else I need to consider please advise.


回答1:


Note that .NET framework 4.0 has support for embedded Primary Interop Assemblies (PIA). You can enable it on the Microsoft.Office.Interop.Word reference by setting the 'Embed Interop Types' to 'True'.
See http://msdn.microsoft.com/en-us/library/dd997297(v=vs.100).aspx for more information about this.

Another way to support multiple Office versions is to use a library like this: http://netoffice.codeplex.com/
The library uses late-binding calls via COM interop and does not require the use of the Primary Interop Assemblies at all.




回答2:


Yes you should refrence the 2007 PIAs since they will work against both Office 2007 and Office 2010. In general you should reference the PIAs for the oldest version of Office that you will support.

You can download the Office 2007 PIAs from here

From MSDN:

When you install and register the Office PIAs in the global assembly cache (either with Office or by installing the redistributable package for the PIAs), the binding redirect assemblies are also installed only in the global assembly cache. These assemblies help make sure that the correct version of the primary interop assemblies are loaded at run time. For example, when a solution that references a 2007 Microsoft Office primary interop assembly runs on a computer that has the Microsoft Office 2010 version of the same primary interop assembly, the binding redirect assembly instructs the .NET Framework runtime to load the Microsoft Office 2010 version of the primary interop assembly.



来源:https://stackoverflow.com/questions/13383250/could-not-load-assembly-interop-word-version-14-0-0-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!