Sheet to image render - A null reference or invalid value was found [GDI+ status: InvalidParameter] in .NET

Testing out Aspose.NET on Mono/C# and running into the following error when trying to do a simple conversion of spreadsheet to image.


A null reference or invalid value was found [GDI+ status: InvalidParameter]

Tried in every available .NET target framework with no luck. Running on Ubuntu 16.04 LTS.

Tried the exact same code on Visual Studio 2015 Windows 10 and it worked fine.

Appears to be some kind of issues with GDI on linux- any insight would be greatly appreciated.

Code below.

using System;
using Aspose.Cells;
using Aspose.Cells.Rendering;
using System.Drawing;

namespace annotate
{
class MainClass
{
public static void Main (string[] args)
{
Workbook workbook = new Workbook ("crocodoc.ods");
Worksheet sheet = workbook.Worksheets[0];

Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
options.HorizontalResolution = 200;
options.VerticalResolution = 200;
options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;

SheetRender sr = new SheetRender (sheet, options);
for (int j = 0; j < sr.PageCount; j++)
{
sr.ToImage(j, "test" + sheet.Name + " Page" + (j + 1) + ".out.tif");
}
}
}
}

Hi Damian,


Thank you for contacting Aspose support. Please share the crocodoc.ods file used for testing on your end. We will perform tests on our side and share the results here.

Document attached

Hi again,


Thank you for sharing the sample spreadsheet. I have evaluated the presented scenario on Ubuntu 15.10 against Mono 4.2.1 and latest version of Aspose.Cells for .NET 17.02.1 (attached). I am afraid, I am not able to replicate the said exception on my side. In fact, I am able to generate all images correctly using your original code. Could you please give a try to the latest version on your end as well? In case the problem persists, please share the version of Mono installed on your system along with complete stack trace of exception for further investigation.

Thanks for that.

I tried referencing the updated DLL and experienced the same issue- however continued to have no issue on Windows/VS2015.

I then decided to try again on a freshly built machine and can get past the Exception error- however the output is garbled, showing only 2-3 lines on a page. I then tried on two other Ubuntu machine with the same results.

Steps to reproduce

Download Ubuntu 16.04 Xenial (Final Version) virtual machine image from OSBoxes website

https://drive.google.com/file/d/0B_HAFnYs6Ur-cWV4WWdTMkIzWDA/view?usp=sharing

Install/open VirtualBox and create a new machine using this disk image

Boot machine and login (Password “osboxes.org”)

After booting go to a terminal and run

sudo apt-get upgrade

sudo apt-get install monodevelop

Download my example project files from here:

https://drive.google.com/file/d/0B-EBn3q7maKdQ0thNVF6blZodVE/view?usp=sharing

Open MonoDevelop

Load the “annotate.sln” solution

Run the code.

The output appears as shown in the attached document.

Interestingly if I comment out the lines that set the Horizontal/Vertical resolution to 200- I just get no content in the JPEG other than the page header.

// options.HorizontalResolution = 200;

// options.VerticalResolution = 200;

I’ve also tried different image formats, upgrading libgdiplus, Ubuntu 16.04 64 bit, Ubuntu 16.04 32 bit. Upgrading Mono to the latest version.

I have attached JPG files with example blank/garbled outputs.

I hope you are able to get to the bottom of the issue as the same code works on Windows VS.NET (although I have a different issue i’ll raise in another post later about images in the spreadsheet not being included in the output JPG), but unfortunately we need this to be installed on existing client servers running as a background process on Ubuntu 16.04 LTS so Mono is the only avenue open to us.

Hi Damian,


Thank you for writing back.

What I understand from your recent post is that you are no longer experiencing the error from your original post while using the latest version of Aspose.Cells for .NET. However, the problem is that your are either getting incomplete rendering or blank pages. Please correct me if I am wrong in my understanding.

That said, I have started downloading the Ubuntu’s VirtualBox image from Google drive. As soon as the download completes, I will perform tests and share my results here.

Thanks, yes that is correct.


The original GDI exception appears to be something specific to this dev machine, as it does not happen when I used a freshly built VM’s with either the current Ubuntu 16.04 LTS ISO or the Osbox image I linked to.

Current issue is either blank, or garbled image being output (which changes depending on if I pass horizontal/vertical resolution parameters or not).

Babar,

Attached is a link to download project files which are more in line with what we are trying to actually build using Aspose (a background daemon that scans and transcodes files to JPEG).

Interestingly Aspose.Words saving as a JPEG works fine- Aspose.Cells still suffers the same problem.

https://drive.google.com/file/d/0B-EBn3q7maKdQlViUmdmdldhV0U/view?usp=sharing

When you run the project it will scan for files in the “queue” folder.

It will then attempt to transcode these to JPG and store the images in the “success” folder.

Interestingly when trying to transcode XLSX files it displays a warning message-

“** (process:13441): WARNING **: Requested 0 bytes. Maximum size for region is 262144 bytes.”

No other conversion display a message.

Hi Damian,

damian.sloane:
Thanks, yes that is correct.

The original GDI exception appears to be something specific to this dev machine, as it does not happen when I used a freshly built VM's with either the current Ubuntu 16.04 LTS ISO or the Osbox image I linked to.

Current issue is either blank, or garbled image being output (which changes depending on if I pass horizontal/vertical resolution parameters or not).

Thank you for the confirmation. I have evaluated both mentioned cases on Ubuntu 16.04 (acquired from Google Drive link) & Mono 4.2.1 against the latest version of Aspose.Cells for .NET 17.02.2 (assembly compiled against .NET framework 4.0), and I am able to notice both problems on my side. In order to further investigate these incidents, I have raised the following tickets for the product team.

  • CELLSNET-45166: SheetRender.ToImage renders only the page header and footer
  • CELLSNET-45167: SheetRender.ToImage renders the contents garbled and incomplete

Please spare us little time to further analyze these scenarios and get back with updates.

Hi again,

dddaaammmooo:

Babar,

Attached is a link to download project files which are more in line with what we are trying to actually build using Aspose (a background daemon that scans and transcodes files to JPEG).

Interestingly Aspose.Words saving as a JPEG works fine- Aspose.Cells still suffers the same problem.

https://drive.google.com/file/d/0B-EBn3q7maKdQlViUmdmdldhV0U/view?usp=sharing

When you run the project it will scan for files in the “queue” folder.

It will then attempt to transcode these to JPG and store the images in the “success” folder.

Interestingly when trying to transcode XLSX files it displays a warning message-

“** (process:13441): WARNING **: Requested 0 bytes. Maximum size for region is 262144 bytes.”

No other conversion display a message.

I have tried your recently shared project and I am able to observe the mentioned warning, however, I am not sure why the message appears and if it is related to Aspose.Cells APIs. Could you please simplify the sample project in a way that we are able to find the source code line and sample document that triggers the issue? Please note, we need aforementioned information for investigation and to log a formal request in our bug tracking system for detailed analysis.

Link below is a sample project similar to the original post. Has three spreadsheets saved in different formats (ODS,XLS,XLSX). XLSX generates a warning, the other two do not generate any warning- but none of them renders to a JPG file correctly.

https://drive.google.com/file/d/0B-EBn3q7maKddVFHbHRYZFBJb00/view?usp=sharing

The warning is generated by this line

sr.ToImage (page, workbook.FileName + “_” + page + “.jpg”);

Also- as with all of my other tests, the same files and code works perfectly when run on Windows/.NET compiled with VS2015 Enterprise

Hi Damian,


Thank you for sharing the simplified sample project. I have evaluated the case against the latest version of Aspose.Cells for .NET 17.02.3 (published a few hours back), and I am able to notice the said warning on Ubuntu 16.04 with Mono 4.2.1. I have raised this incident with the product team under the ticket CELLSNET-45169. Please spare us little time to further investigate the matter and get back with updates in this regard.

Hi again,


This is to update you that all the tickets attached to this thread have been marked resolved. We will shortly share the fix here for your testing.

Babar,


Thanks for the prompt reply, I look forward to the fix.

Regards,
Damian

Hi Damian,


Please give a try to the latest version of Aspose.Cells for .NET 17.02.6 (attached) and share your feedback.

The issues you have found earlier (filed as CELLSNET-45169;CELLSNET-45167;CELLSNET-45166) have been fixed in Aspose.Cells for .NET 17.3.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.