0

I'm trying to run an old Project which was written years ago on a new System. It's an .NET Project and it has references to Microsoft.Office.Interop.Excel, ...Outlook, ...Word, etc.

When i run the programm i get the Error message "The file or assembly "Interop.Microsoft.Office.Core" or a dependency of it was not found. An attempt was made to load a file with an incorrect format."

=== State information before binding ===
LOG: DisplayName = Interop.Microsoft.Office.Core
 (Partial.)
WRN: Partial binding information was provided for an assembly:
WRN: Assembly name: Interop.Microsoft.Office.Core | Domain ID: 2
WRN: Partial binding occurs when only part of the assembly display name is provided.
WRN: This may cause the collection folder to load an incorrect assembly.
WRN: Specify the text identity of the assembly with full details. 
WRN: This includes the simple name, version and culture, and public key token.
WRN: For more information and general solutions to this problem, see the whitepaper at "http://go.microsoft.com/fwlink/?LinkId=109270".
LOG: Appbase = file:///C:/Users/krebesli/OneDrive - TRUMPF SE + Co. KG/Project - Copy/TruTopsSales/TruTopsSales/
LOG: Original PrivatePath = C:\Users/krebesli/OneDrive - TRUMPF SE + Co. KG\Project - copy\TruTopsSales\TruTopsSales\bin
Call from Assembly : (Unknown).
===
LOG: This binding starts in default load context.
LOG: The application configuration file is used: C:\Users\krebesli\OneDrive - TRUMPF SE + Co. KG\Project - copy\TruTopsSales\TruTopsSales\web.config.
LOG: The host configuration file is used: \srvditz1\home$\krebesli\Documents\IISExpress\config\aspnet.config.
LOG: The computer configuration file of C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config is used.
LOG: policy is not currently applied to the reference (private, custom, partial, or path-based assembly binding).
LOG: download of new URL file:///C:/Users/(username)/AppData/Local/Temp/Temporary ASP.NET Files/vs/2636e7dd/88283cb5/Interop.Microsoft.Office.Core.DLL.
LOG: Download of new URL file:///C:/Users/(username)/AppData/Local/Temp/Temporary ASP.NET Files/vs/2636e7dd/88283cb5/Interop.Microsoft.Office.Core/Interop.Microsoft.Office.Core.DLL.
LOG: Download from new URL file:///C:/Users/(username)/.../.../.../bin/Interop.Microsoft.Office.Core.DLL.
ERR: Assembly setup could not be completed (hr = 0x8007000b). The search was terminated.

I don't know whats wrong. I never use the Interop.Microsoft.Office.Core in my Code

What i've tried so far:

  • Delete the reference to Microsoft.Office.Core -> Error still occurs
  • Delete all .Office References and add Microsoft Office 16.0 Object Library from reference Manager -> COM

Does anyone have any clues what i can do? I dont know why this error occurs...

Do i maybe need to install office again. Or maybe .NET again.

Maybe somethings wrong with that...

references

COM Tab

EDIT:

When i search for "office" in the reference tab it doesnt find anything as you can see here

Search for "office"

I think the problem could be that when i look at the properties of the office.core reference it says local copie: false.

Copy Local - false

but i also cant change that setting...

Linus _20
  • 49
  • 4
  • It was part of the [Office Primary Interop Assemblies](https://learn.microsoft.com/en-us/visualstudio/vsto/office-primary-interop-assemblies?view=vs-2022). Microsoft no longer provides them since .NET 4.0, they now prefer that you [embed them](https://stackoverflow.com/questions/21013912/can-i-still-use-microsoft-office-interop-assemblies-with-office-2013). – Hans Passant Jun 13 '22 at 14:24
  • did embed them via the add reference menue in visual studio – Linus _20 Jun 13 '22 at 14:32
  • so it should work but it doesnt – Linus _20 Jun 13 '22 at 14:33
  • My guess is the DLLs are 32 bit but your app is 64 bit, or vice versa. – mason Jun 13 '22 at 14:36
  • Follow the guidance in the linked Q+A, you **must** add the COM reference to properly embed them. You then get office.dll embedded, not Interop.Microsoft.Office.Core.dll – Hans Passant Jun 13 '22 at 14:36
  • @HansPassant Where can i find that Q + A or can you explain further how i embedd the COM reference – Linus _20 Jun 14 '22 at 12:16
  • Click on the blue underlined words in the first comment. – Hans Passant Jun 14 '22 at 12:28
  • i did add my references via the COM tab. I added the microsoft office 16.0 object library. So thats what it says in the Q + A but the same error still occurs and it embedds the microsoft.office.core.dll – Linus _20 Jun 14 '22 at 12:38

1 Answers1

0

You need to add a reference anew if you change the target framework or upgrade the project to using .net core. You can add the COM references straight from the IDE (since Visual Studio 2019 v16.6). Or you can do that manually, for that you need to create a new .NET Framework 4.X project. Add the relevant COM references to the project. Edit the .csproj of your .NET Core 3.0 project and add the generated references from the .NET Framework project to the <ItemGroup> tag.

It should look like that:

<ItemGroup>
    <COMReference Include="Microsoft.Office.Core">
      <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
      <VersionMajor>2</VersionMajor>
      <VersionMinor>8</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>primary</WrapperTool>
      <Isolated>False</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>

... more references

</ItemGroup>

See .NET core 3.0 and MS Office Interop for more information.


The Interop.Microsoft.Office.Core assembly is added when you add any Office-specific COM reference to the project. You just need to make sure the file is copied locally to the output folder of your project.

If it is still not added automatically, you may try to find such entry in the COM References dialog of Visual Studio, look for the office entry in the list:

enter image description here

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45