Skip to content

Incorrect COMReference entry when using Office interop #5735

@JohnyL

Description

@JohnyL

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>.

Metadata

Metadata

Assignees

Labels

Bug BashIssues to be handled during our bug fixing pushNeeds-CPS-workChanges are needed in the closed-source Common Project System (CPS) repo.Parity-Legacy-FeatureMissing features from the legacy project system.Triage-ApprovedReviewed and prioritized

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions