我正在将我的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.
奇怪的是我的引用看起来都一样,除了一个引用:在.NET 3.5项目中有一个引用到类型为COM,版本为1.6.0.0的
Microsoft.Office.Interop.Excel
(它来自GAC),但我无法在.NET 4.5.1项目中重新创建此引用,因为在COM对象引用中没有这样的东西,而且我在.NET引用中找不到这个版本。不知道这是否会导致问题。您有任何想法如何让它在.NET 4.5.1上工作吗?