3

[C# 4.6 on VS 2017]

We are currently migrating our Csproj from the old format to the new format (obviously), and we are facing a weird issue.

One project is using the Microsoft.Office.Interop.Excel assembly. At some point we manipulate Excel Range attributes like this:

public static void ApplyGradient(Range rng)
{
    rng.FormatConditions[1].ColorScaleCriteria[1].FormatColor.TintAndShade = 0;
}

When browsing to the assembly from VS, we observe different Microsoft.Office.Interop.Excel signatures in old and new projects. Here is what we see:

The result is a compilation issue, in the new version of csproj, because ColorScaleCriteria is not understood as a property of object obviously.

We have tried several actions, like adding the System.Dynamic.Runtime dependency in our project, but it did not solve anything.

Any help would be greatly appreciated. Many thanks!

RedRise
  • 31
  • 2

1 Answers1

2

Probably after two+ years this is not relevant anymore, but for people that are facing the same problem:

You need to remove the NuGet reference to Bundle.Microsoft.Office.Interop / Microsoft.Office.Interop.Excel.

Add the COM Reference to Microsoft Excel 16.0 Object Library and set Copy Localand Embed Interop Types to Yes.

Or you can just add this to your .csproj file:

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

Got the solution from this thread: https://stackoverflow.com/a/59138607