c# - 从 .NET 3.5 更改为 4.5.1 时无法加载文件或程序集 'Interop.Microsoft.Office.Core, Version=2.4.0.0, ...'

标签 c# .net vb.net office-interop

我正在将我的 WinForms 应用程序从 .NET 3.5 升级到 4.5.1。
3.5 应用程序运行良好。升级到 .NET 4.5.1 后,我开始收到以下异常:

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.

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


FusionLog 说:
=== 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 项目中有一个对 Microsoft.Office.Interop.Excel 的引用。类型 COM和版本 1.6.0.0 (它来自 GAC)我无法在 .NET 4.5.1 项目上重新创建,因为 COM 对象引用中没有这样的东西,而且我在 .NET 引用中找不到这个版本。
不知道这是否导致问题。
关于如何让它与 .NET 4.5.1 一起工作的任何想法?

最佳答案

您运行的 .Net 框架版本无关紧要。看来您需要重新添加引用。看看 COM Visual Studio 的“添加引用”对话框中的选项卡。互操作程序集将自动为您生成。

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

enter image description here

无论如何,Could not load file or assembly Microsoft.Office.Interop.Excel论坛帖子描述了完全相同的错误。

关于c# - 从 .NET 3.5 更改为 4.5.1 时无法加载文件或程序集 'Interop.Microsoft.Office.Core, Version=2.4.0.0, ...',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28349576/

相关文章:

c# - 如何使用 C# 确定 BlobClient 是否用于 Azure SDK12 中的快照?

c# - 混淆 if(something){} 和 if(something == true){}

c# - Selenium 2/Webdriver - 如何双击表格行(打开一个新窗口)

c# - 如何在 XAML 中设置 DataGrid 的 ItemsSource?

c# - ToolStripMenuItem 和 Control 的共享基础?

jquery - 如何从自动完成jquery函数中获取所需的值?

c# - 打开 PDF 文档并为其添加书签

c# - 在为 ASP.NET MVC 2.0 应用程序注册区域时提供或过滤程序集

.net - 单击一次-所有用户

vb.net - 如何用x个字符分割字符串