0

I have seen this post because I have a similar error but with another library.

I have project with .NetFramework 4.6.1, and I have done another project with test that uses .net Core 2.0 in Visual Studio 2017. When i have to test a method that uses the package Microsoft.Office.InteropExcel it fails when trying to open the excel because it has not been loaded well.

The library gives a similar warning, so I suppose this is the error.

enter image description here

ParserTests.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <OutputPath>bin\Release\</OutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputPath>bin\Debug\</OutputPath>
  </PropertyGroup>

  <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>
      <Private>true</Private>
    </COMReference>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
    <PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1000" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
    <PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="NPOI" Version="2.5.3" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\BalanceParserTool\BalanceParserTool.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="System.Windows.Forms">
      <HintPath>C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll</HintPath>
    </Reference>
  </ItemGroup>

</Project>

How can I solve the problem in my case?

This is the error that give me a test that use that library:

enter image description here

  • 1
    Do any of these answers: https://stackoverflow.com/questions/58130446/net-core-3-0-and-ms-office-interop work for you? – T.Schwarz Jun 30 '21 at 11:48
  • I have put the csproj as it says in the post and I still receive the error. I have put the csproj in the question if you want to see it – Enrique González Jun 30 '21 at 12:53
  • This may be helpful: https://social.msdn.microsoft.com/Forums/vstudio/en-US/690930f1-7856-4f5f-b073-6cf2c40baa19/microsoftofficeinteropexcel-with-net-core?forum=netfxbcl – Tu deschizi eu inchid Jun 30 '21 at 15:01
  • I have done also that and nothing @user9938 :( – Enrique González Jun 30 '21 at 15:28
  • 1
    @EnriqueGonzález: Using interop is slow and there are better alternatives these days. What are you trying to accomplish? Read an Excel file? Write an Excel file? What is the file extension (ex: .xlsx)? You might consider using NuGet package `DocumentFormat.OpenXml`. – Tu deschizi eu inchid Jun 30 '21 at 15:43
  • @user9938 I want to modify a custom property from c#, from interop i was using a macro to modify it, i do not know how to modify it with this library, it is a bit complex :( – Enrique González Jul 02 '21 at 12:08
  • Can you elaberate on your custom property? What is the file extension of the Excell file? Does it use macros? – Tu deschizi eu inchid Jul 02 '21 at 13:57
  • See if this is helpful: https://stackoverflow.com/questions/58130446/net-core-3-0-and-ms-office-interop – Tu deschizi eu inchid Jul 02 '21 at 13:57
  • I have dropped the Interop, now I am using the one you said because it has the dependencies fine to work on .NET Core 2.1. I am using excels with extension .xslm, so it uses macros. I followed this post (https://learn.microsoft.com/es-es/office/open-xml/how-to-set-a-custom-property-in-a-word-processing-document) to modify the custom property I want, but I have to change the format ID and the pid without knowing what it is, but if I do not do it, it does not work (I used the format id and the pid exactly as the post) – Enrique González Jul 05 '21 at 07:10

0 Answers0