question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect COMReference entry when using Office interop

See original GitHub issue

To include Excel interop libraries in .NET Core app, I do the following: Dependencies -> Add Reference -> COM -> Microsoft Excel 14.0 Object Library. When I do this, I get the following ItemGroup:

<ItemGroup>
    <COMReference Include="Microsoft.Office.Excel.dll">
        <Guid>00020813-0000-0000-c000-000000000046</Guid>
        <VersionMajor>1</VersionMajor>
        <VersionMinor>7</VersionMinor>
        <WrapperTool>tlbimp</WrapperTool>
        <Lcid>0</Lcid>
        <Isolated>false</Isolated>
    </COMReference>
</ItemGroup>

However, I get the following runtime error:

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly ‘office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’. The system cannot find the file specified.

In order to work, I have created .NET Framework app, added COM reference there and copied its COMReference - and it works:

<ItemGroup>
    <COMReference Include="Microsoft.Office.Interop.Excel">
        <Guid>{00020813-0000-0000-C000-000000000046}</Guid>
        <VersionMajor>1</VersionMajor>
	<VersionMinor>7</VersionMinor>
	<Lcid>0</Lcid>
	<WrapperTool>primary</WrapperTool>
	<Isolated>False</Isolated>
	<EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
</ItemGroup>

As noted here, in order to fix the situation, the project system needs to add <EmbedInteropTypes>True</EmbedInteropTypes>.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
shanselmancommented, Sep 14, 2020

I’m hitting this, just as above, in Sept of 2020. @davkean

Seems like you can’t do Office Interop with Core unless you do the com reference manually?

Tooling does this (wrong:)

    <COMReference Include="Microsoft.Office.PowerPoint.dll">
      <Guid>91493440-5a91-11cf-8700-00aa0060263b</Guid>
      <VersionMajor>2</VersionMajor>
      <VersionMinor>12</VersionMinor>
      <WrapperTool>tlbimp</WrapperTool>
      <Lcid>0</Lcid>
      <Isolated>false</Isolated>
    </COMReference>
  </ItemGroup>

Correct:

    <COMReference Include="Microsoft.Office.Interop.PowerPoint">
      <Guid>{91493440-5a91-11cf-8700-00aa0060263b}</Guid>
      <VersionMajor>2</VersionMajor>
      <VersionMinor>12</VersionMinor>
      <WrapperTool>primary</WrapperTool>
      <Lcid>0</Lcid>
      <Isolated>false</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
  </ItemGroup>
6reactions
drewnoakescommented, Dec 16, 2019

Repro steps:

  1. New netcoreapp3.1 console application
  2. Right-click Dependencies node
  3. Select “Add Reference…”
  4. Select “COM”
  5. Select “Microsoft Excel 16.0 Object Library”
  6. Reference a type within code (e.g. Microsoft.Office.Interop.Excel.Chart)
  7. Try to run the console app. It fails as described.
  8. Add <EmbedInteropTypes>True</EmbedInteropTypes>
  9. Running now works

netcoreapp3.1

  <ItemGroup>
    <COMReference Include="Microsoft.Office.Excel.dll">
      <Guid>00020813-0000-0000-c000-000000000046</Guid>
      <VersionMajor>1</VersionMajor>
      <VersionMinor>9</VersionMinor>
      <WrapperTool>tlbimp</WrapperTool>
      <Lcid>0</Lcid>
      <Isolated>false</Isolated>
    </COMReference>
  </ItemGroup>

net471

  <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>
    <COMReference Include="Microsoft.Office.Interop.Excel">
      <Guid>{00020813-0000-0000-C000-000000000046}</Guid>
      <VersionMajor>1</VersionMajor>
      <VersionMinor>9</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>primary</WrapperTool>
      <Isolated>False</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
    <COMReference Include="VBIDE">
      <Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
      <VersionMajor>5</VersionMajor>
      <VersionMinor>3</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>primary</WrapperTool>
      <Isolated>False</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
  </ItemGroup>
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Can't get Microsoft.Office.Interop reference to work
Use NuGet Package Manager in VS2015. Right click references in your visual studio project; Select Manage NuGet Packages ...
Read more >
Problem with Microsoft.Office.Interop.Excel
Hello,. I have simple code to open a excel. But I couldn't open it.. I googled about this interop problem and tried every...
Read more >
How to access Office interop objects - C# guide
Learn about C# features that simplify access to Office API objects. Use the new features to write code that creates and displays an...
Read more >
Imports Microsoft.Office.Interop flagged as warning, not ...
I was able to repro the problem with the same entries in the registry, Win32 pointing to a bad location and Win64 points...
Read more >
Studio - Microsoft Office Interop Issues
Causes. Microsoft Office installation issues may result in incorrect COM Interop configurations in the Windows registry. For example, this may ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found