当从.NET 3.5更改为4.5.1时,无法加载文件或程序集'Interop.Microsoft.Office.Core,版本= 2.4.0.0,...'

问题描述 投票:0回答:2

我正在将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,版本= 2.4.0.0,区域性=中性,PublicKeyToken =空'

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和版本为COM1.6.0.0的引用(它来自GAC),我无法在.NET 4.5.1项目上重新创建,因为COM对象参考中没有此类内容,并且我无法在.NET参考中找到此版本。

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

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

c# .net vb.net office-interop
2个回答
4
投票

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

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

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9pT0RUWC5wbmcifQ==” alt =“在此处输入图像描述”>

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


0
投票

我解决了将“复制本地”和“嵌入互操作类型”设置为true的问题。

((我安装了Office 2013和365)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.