Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am upgrading my WinForms application from .NET 3.5 to 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: 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 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.

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.

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

like image 478
Denis Avatar asked Sep 08 '25 08:09

Denis


2 Answers

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.

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

enter image description here

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

like image 54
Eugene Astafiev Avatar answered Sep 09 '25 20:09

Eugene Astafiev


I solved setting "Copy Local" and "Embed Interop Types" to true.

(I have Office 2013 and 365 installed)

enter image description here

like image 31
Nuno Ribeiro Avatar answered Sep 09 '25 20:09

Nuno Ribeiro