从.NET 3.5更改为4.5.1时无法加载文件或程序集'Interop.Microsoft.Office.Core,Version = 2.4.0.0,...' [英] Could not load file or assembly 'Interop.Microsoft.Office.Core, Version=2.4.0.0, ...' when changing from .NET 3.5 to 4.5.1

查看:486
本文介绍了从.NET 3.5更改为4.5.1时无法加载文件或程序集'Interop.Microsoft.Office.Core,Version = 2.4.0.0,...'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将WinForms应用程序从.NET 3.5升级到4.5.1.

I am upgrading my WinForms application from .NET 3.5 to 4.5.1.

3.5应用程序正常工作.升级到.NET 4.5.1之后,我开始收到以下异常:

The 3.5 application works just fine. After the upgrade to .NET 4.5.1 I started getting the following exception:

System.IO.FileNotFoundException:无法加载文件或程序集"Interop.Microsoft.Office.Core,版本= 2.4.0.0,区域性=中性,PublicKeyToken =空"或其依赖项之一.系统找不到指定的文件.

System.IO.FileNotFoundException: Could not load file or assembly 'Interop.Microsoft.Office.Core, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

文件名:'Interop.Microsoft.Office.Core,Version = 2.4.0.0,Culture = neutral,PublicKeyToken = null'

File name: 'Interop.Microsoft.Office.Core, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null'

FusionLog说:

FusionLog says:

=== Pre-bind state information ===
LOG: DisplayName = Interop.Microsoft.Office.Core, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/SampleApp/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Interop.Microsoft.Office.Interop.Excel, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\SampleApp\bin\Debug\SampleApp.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/SampleApp/bin/Debug/Interop.Microsoft.Office.Core.DLL.
LOG: Attempting download of new URL file:///C:/SampleApp/bin/Debug/Interop.Microsoft.Office.Core/Interop.Microsoft.Office.Core.DLL.
LOG: Attempting download of new URL file:///C:/SampleApp/bin/Debug/Interop.Microsoft.Office.Core.EXE.
LOG: Attempting download of new URL file:///C:/SampleApp/bin/Debug/Interop.Microsoft.Office.Core/Interop.Microsoft.Office.Core.EXE.

奇怪的是,除1个引用外,我的引用看起来相同:在.NET 3.5项目中,有对类型COM和版本1.6.0.0Microsoft.Office.Interop.Excel的引用(来自GAC)我无法在.NET 4.5.1项目上重新创建该版本,因为COM对象参考中没有这样的东西,而我在.NET参考中找不到此版本.

The strange part is that my references look the same except for 1 reference: in the .NET 3.5 project there was a reference to Microsoft.Office.Interop.Excel of Type COM and version 1.6.0.0 (it was coming from the GAC) which I can't re-create on the .NET 4.5.1 project as there is no such thing in the COM Object References and I can't find this version in the .NET references.

不知道这是否是导致问题的原因.

Don't know if that is contributing to the problem.

关于如何使它与.NET 4.5.1一起使用的任何想法?

Any ideas on how I can get this to work with .NET 4.5.1?

推荐答案

运行什么.Net框架版本都没有关系.看来您需要重新添加参考.在Visual Studio的添加引用"对话框中,查看 COM 选项卡.互操作程序集将自动为您生成.

It doesn't matter what .Net framework version you run. It looks like you need to re-add the reference. Take a look at the COM tab in the Add Reference dialog of Visual Studio. The interop assembly will be generated for you automatically.

请特别注意刚刚添加的引用的Embedd Interop Types属性:

Pay special attention to the Embedd Interop Types property of the just added references:

无论如何,

Anyway, the Could not load file or assembly Microsoft.Office.Interop.Excel forum thread describes exactly the same error.

这篇关于从.NET 3.5更改为4.5.1时无法加载文件或程序集'Interop.Microsoft.Office.Core,Version = 2.4.0.0,...'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆