Aspose.Cells looking for old version of System.Drawing.Common on .net6 projects

I have a .Net6 project using many of the Aspose libraries (latest versions) brought in from the Nuget packages available on nuget.org. According to the documentation for net6.0 projects, Aspose.Cells have a dependency on System.Drawing.Common (>= 4.7.0) and I have confirmed that the only version on my system is 5.0.421 (image attached). However, when opening a workbook Aspose.Cells throws the this exception:

System.Exception: Unable to open the Excel document.
: Could not load file or assembly ‘System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The system cannot find the file specified.
at DocumentExpander.Office.ExcelExpander.OpenWorkbook(Stream stream) in C:\Git_Repos\AWSScratch\FileAnalyzer\DocumentExpander\Office\ExcelExpander.cs:line 65

Steps to recreate:

  1. Start with a system that only has .net6 installed on it (mine is a Windows Server 2019 image where I installed .net6)
  2. Create a test program that opens an Excel workbook using the below code:
public Workbook OpenWorkbook(Stream fileStream)
{
    try
    {
        var opt = new LoadOptions
        {
            MemorySetting = MemorySetting.MemoryPreference,
        };
        return new Workbook(stream);
    }
    catch (Exception ex)
    {
        throw new Exception(string.Format("Unable to open the Excel document.\n<Error>: {0}", ex.Message));
    }
}

MySystemDrawingDllVersion.jpg (120.6 KB)

@wingswin1,

I tested your scenario/case on Windows 10. I opened a new console application (target framework set to .NET 6.0) in Visual Studio 2022. I then opened Nuget Package Manager and searched Aspose.Cells 22.3 latest version. I selected it and installed it. When the package is installed it automatically installs Aspose.Cells.Dll, System.Drawing.Common (4.7.0) and System.Text,Encoding.CodePages (4.7.0) under the packages in the project. I then write following simplest sample code and it works fine. I read a template XLSX file which has charts and other drawing objects in it. I simply opened it into Aspose.Cells object model and then add/update a value in a worksheet and re-save the file. It works fine and output file is fine tuned.
e.g.
Sample code:

Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(new FileStream("f:\\test2\\Book1.xlsx"));
wb.Worksheets[0].Cells["A1"].PutValue("testin...");
wb.Save("f:\\test2\\out1.xlsx");

I think you should install latest version of Aspose.Cells for .NET v22.3 from nuget package as it will automatically install all the correct dependencies and then give it a try to your sample, it should work fine.

Yes, on my Win10 desktop it appears to work perfectly fine. I’m attempting to run this in a Windows Server 2019 docker container and it is causing errors looking for System.Drawing.Common.dll. I have done a little more testing with other Aspose products and found that some work and some don’t, and those that don’t do not produce the same error. It seems very odd to me that each of the failing libraries is looking for a different version of System.Diagram.Common. I have tested with multiple versions of System.Diagram.Common from 4.7 thru 6.0 and they all produce the exact same results.

Here is what I have found during testing:

  • Aspose.Words 22.3.0 - works without issue

  • Aspose.Email 22.2.0 - works without issue

  • Aspose.Cells 22.3.0 - System.Exception: Unable to open the Excel document.
    : Could not load file or assembly ‘System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The system cannot find the file specified.

  • Aspose.Diagram 22.3.0 - Aspose.Diagram.DiagramException: Error in element VisioDocument in \VisioDocument. Error in element Colors in \VisioDocument\Colors. Could not load file or assembly ‘System.Drawing.Common, Version=4.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The system cannot find the file specified.

  • Aspose.Slides.NET 22.2.0 - System.TypeInitializationException: The type initializer for ‘Aspose.Slides.Presentation’ threw an exception.
    —> System.IO.FileNotFoundException: Could not load file or assembly ‘System.Drawing.Common, Version=5.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The system cannot find the file specified.

  • Aspose.PDF 22.2.0 - works without issue

@wingswin1,

Thanks for providing details and test results.

We have logged a ticket with an id “CELLSNET-50639” for your issue. We will investigate and look into the details of your issue.

Once we have an update on it, we will let you know.

If it helps, here’s the dockerfile that I have been testing with

# escape=`

FROM mcr.microsoft.com/windows/servercore:ltsc2019

RUN powershell -Command `
        $ErrorActionPreference = 'Stop'; `
        $ProgressPreference = 'SilentlyContinue'; `
        Invoke-WebRequest `
            -UseBasicParsing `
            -Uri https://dot.net/v1/dotnet-install.ps1 `
            -OutFile dotnet-install.ps1; `
        ./dotnet-install.ps1 `
            -InstallDir '/Program Files/dotnet' `
            -Channel 6.0 `
            -Runtime dotnet; `
        Remove-Item -Force dotnet-install.ps1 `
    && setx /M PATH "%PATH%;C:\Program Files\dotnet"

# Copy test code into container
WORKDIR	/app
COPY <location of compiled test code> ./

@wingswin1,

Thanks for the docker file.

I have logged it with your existing ticket “CELLSNET-50639” and sure, it may help in evaluating your issue.

Hi @wingswin1
I wrote a simple program with a dockerfile, can run successfully, please refer to, and please tell us your feedback, thank you.
Net6TestDocker2.zip (24.9 KB)

I was able to confirm that building the solution inside the Docker file works as expected, but building it outside and copying the binaries inside causes the behavior that I was seeing.

Do you know why it is required to build inside the container? It was confusing to me because Aspose.Words and Aspose.Email work fine building outside and then copying the binaries into the container for execution.

Hi @wingswin1
After comparison, I found that Aspose.Words and Aspose.Email did not quote “System.Drawing.Common”, That’s probably why they don’t get the error.

For Aspose.Cells, It is possible that after doing “outside building”, Some of the library files that system.drawing.common needed had not been fully copied, causing problems.
It is recommended that you build it inside a container to avoid some environmental problems.

Hi, I am also encountering the same issue.

Can I check if there are any updates to CELLSNET-50639? Or any ETC to when the fix will be implemented?

Thank you!

@ivanoh,

We closed the ticket as “Won’t Fix” that means we will not fix the issue. The user already shared/confirmed in his reply that he has figured it out as he mentioned: