【发布时间】:2015-02-05 16:50:43
【问题描述】:
我正在将我的 WinForms 应用程序从 .NET 3.5 升级到 4.5.1。
3.5 应用程序运行良好。升级到 .NET 4.5.1 后,我开始收到以下异常:
System.IO.FileNotFoundException:无法加载文件或程序集“Interop.Microsoft.Office.Core,Version=2.4.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。系统找不到指定的文件。
文件名:'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 一起工作的任何想法?
【问题讨论】:
-
你不能重新添加引用来更正它们吗?
-
@Mike:尝试过,重新添加了对“Microsoft Office 12.0 对象库”(COM,版本:2.4.0.0)的引用,但我找不到另一个引用。不用说没有帮助。似乎在运行时找不到它。它编译得很好。
-
office是什么版本的?
-
只是为了验证,您是否选择了客户端配置文件或框架 4?
-
我所做的只是在 VS2013 的“应用程序”选项卡中的“.NET Framework 3.5”和“.NET Framework 4.5.1”之间切换目标框架。不是客户资料。
标签: c# .net vb.net office-interop