We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

The file is corrupted. - FileFormatUtil

Hi Guys,

I have a strange behavior when I use the class “FileFormatUtil” in dotnet core.
In .NET 452, calling the following method works fine.
If I call this in .NET Core 2.1 the following error message appears.
“The file is corrupted.”
Can you take a look what the problem is.

Thank you for your support.


Do you use the same file on both .NET framework versions (e.g .NET Core and .NET Framework 4.5.2)? It should work equally fine on .NET Core (if it is working on normal .NET Framework version).

Anyways, I would recommend you to kindly try our latest version/fix (attached) in your .NET Core project: Aspose.Cells for .NET v18.8.1 (for .NET Standard 2.0) Aspose.Cells18.8.1 For .NetStandard20.Zip (3.8 MB)

If you still find the issue with v18.8.1, kindly do provide your template file, we will check it soon.

Hi Amjad Sahi,

I have attached an example with which you can test.
AsposeCellsTest.zip (3.7 MB)
This uses the Aspose.Cells version 18.8.1.
You can run the .NET Core 2.1 app directly in the debug directory.
Or open the code in Visual Studio, but you still need to link the reference to Aspose.Cells new.
My Path to Aspose.Cells is a another.
When you start the application, an exception is thrown in line 18.

Thank you for your support.


Thanks for the sample project.

After an initial test using your sample code and template file in a .NET Core project, I am able to observe the issue as you mentioned (Even we can use any template file). The FileFormatUtil API to detect file format is not working on .NET Core. It gives error that file is corrupted. If we use the APIs on normal .NET framework version (2.0, 4.x, etc.), it works fine.

I have logged a ticket with an id “CELLSNET-46320” for your issue. We will look into it soon.

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


We evaluated your issue further.

Well, for your information, Aspose.Cells18.8.x for .NetStandard20 demands to install System.Drawing.Common and System.Text.Encoding.CodePages APIs. So, you should install these APIs as well from NuGet when you refer to Aspose.Cells lib manually in the project. Alternatively, you can get/install Aspose.Cells from NuGet as these APIs will be installed automatically. Now, after you have installed System.Text.Encoding.CodePages, .NetCore program needs to call this method to register encoding Provider, see the line of code which you need to add at the start:
You need to call this before you call “FileFormatUtil.DetectFileFormat” APIs, it will fix your issue as I tested.

In Aspose.Cells v18.8.x, we init it in the constructor method of the Workbook class. If you have not init a Workbook first, the problem will occur for sure. From the next version, we will provide a “CellsHelper.InitForDotNetCore()” method, and suggest you to call it first for all .NetCore initializations
Sample code:

var info = FileFormatUtil.DetectFileFormat("C:\\Users\\amjad\\source\\repos\\AsposeCellsTest\\AsposeCellsTest\\Resources\\TestDoc.xlsx");
//Gets the detected load format
Console.WriteLine("The spreadsheet format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat));

Let us know if you still find any issue.


thank you for this information.
I have tested and it works. :slight_smile:

Thank you for your support.


Good to know that your issue is sorted out by the suggested line of code. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.