openxml-sdk.net-9.0

OpenXML SDK failing with a InvalidProgramException


I am using OpenXML SDK version 2.91 in a .NET 9 application. All nuget packages are the latest version.

When I call this method (I have written):

private void AddColumnValue(string columnValue, Row row)
{
    Cell cell = new Cell();
    cell.DataType = CellValues.String;
    cell.CellValue = new CellValue(columnValue);
    row.AppendChild(cell);
}

I get an error

Common Language Runtime detected an invalid program. - System.InvalidProgramException: Common Language Runtime detected an invalid program.

I assume that it is triggered by using Row as parameter.

I have cleaned all binaries (including all nuget caching). I have tried to change versions of .NET and versions of the OpenXML SDK and I still get the same error. I have tried to rewrite the code but all versions throw a System.InvalidProgramException. I have no ideas left.

The stack trace is:

Common Language Runtime detected an invalid program. - System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at HcmErpOpenXmlHelpers.Services.ExcelWriterService.AddColumnValue(String columnValue, Row row)
   at HcmErpOpenXmlHelpers.Services.ExcelWriterService.AddRow(String[] values) in C:\tfs\HcmErpUtil\HcmErpUtilOpenXmlHelpers2\Services\ExcelWriterService.cs:line 98
   at HcmErpOpenXmlHelpers.Services.ExcelWriterService.GenerateExcelFile[T](String fileName, List`1 list, String[] headers, Func`4 valueAdapterFunc) in C:\tfs\HcmErpUtil\HcmErpUtilOpenXmlHelpers2\Services\ExcelWriterService.cs:line 69
   at HcmErpUtilQlikviewFileUpdater.Services.QlikViewFileUpdateService.UpdateQlikViewFileAsync(String csvFileName, String excelFileName, CancellationToken cancellationToken) in C:\tfs\HcmErpUtil\HcmErpUtilQlikviewFileUpdater\Services\QlikViewFileUpdateService.cs:line 66
   at HcmErpUtilFacade.UseCases.UpdateQlikViewFile(String csvFileName, String excelFileName, CancellationToken cancellationToken) in C:\tfs\HcmErpUtil\HcmErpUtilFacade\UseCases.cs:line 90
   at HcmErpUtilConsole.HostedService.<>c__DisplayClass14_0.<SetupUpdateQlikViewFiles>b__0() in C:\tfs\HcmErpUtil\HcmErpUtilConsole\HostedService.cs:line 254
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass143_0.<OnExecute>b__0(CancellationToken _)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at HcmErpUtilConsole.HostedService.ExecuteAsync(CancellationToken unusedCancellationToken) in C:\tfs\HcmErpUtil\HcmErpUtilConsole\HostedService.cs:line 66

It only contains references to my code except that AddColumnCode has a Row as parameter

PS. I have also tried .NET8, .NET6, .NET Standard 2.1 and .NET Standard 2.0. I have also tried various versions of the OpenXML SDK package.


Solution

  • For now I have reintroduced an older version where the entire solution is .NET6 based and that seems to solve the problem for now.