Images with TargetMode="External" result in System.NullReferenceException

The attached WithImage.zip (6.6 KB) XLSX document contains an external reference to an image. The path to the image is file:///C:\tools\Finn.png and no matter whether file is there or not Aspose.Cells throws System.NullReferenceException during conversion to CSV. Here is the code.

var doc = new Aspose.Cells.Workbook(inputStream);
doc.Worksheets.ActiveSheetIndex = 0;
doc.Worksheets[0].AutoFitRows(true);
var options = new Aspose.Cells.TxtSaveOptions
                  {
                      Separator = Convert.ToChar(";")
                  };
doc.Save(outputStream, options);

inputStream and outputStream are instances of System.IO.Stream.

@volozyko,
I can not reproduce the issue with Aspose.Cells for .NET 20.9 version. Could you please test with latest version and let us know your feedback. If issue occurs then also include your runnable code related to inputStream and outputStream.

I did use Aspose.Cells for .NET 20.9 and if it makes any difference I used the dll for .NET 4.0 on Window 10 x64.

Concerning, the piece of code to reproduce it. I will have to extract it. In general, we invoke Aspose.Cells from C++ code loading the whole file in System.IO.MemoryStream. Can it be the problem? Loading external references naturally needs a path to the currently loaded file.

@volozyko,
Looks like the problem is with loading of file into the stream. I have tried to load it with following code which works fine on our end.

string inputFile = path + "WithImage.xlsx";
byte[] filearray = null;
FileStream file = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
BinaryReader binaryReader = new BinaryReader(file);
long size = new FileInfo(inputFile).Length;
filearray = binaryReader.ReadBytes((int)size);
Stream inputstream = new MemoryStream(filearray);

Stream outputStream = new MemoryStream();
var doc = new Aspose.Cells.Workbook(inputstream);
doc.Worksheets.ActiveSheetIndex = 0;
doc.Worksheets[0].AutoFitRows(true);
var options = new Aspose.Cells.TxtSaveOptions
{
    Separator = Convert.ToChar(";")
};
doc.Save(outputStream, options);

Indeed, there is nothing thrown in the code above. My fault. I discovered that the original file is converted on the fly with our code and the file which is actually supplied to Aspose.Cells is a bit different. See the new file WithImage3.zip (7.2 KB). I played with this new file and identified that the problem is in the following in xl/drawings/drawing1.xml:

  <xdr:blipFill>
    <a:blip r:embed="" r:link="rId1"/>
    <a:stretch/>
  </xdr:blipFill>

If I remove r:embed="" then Aspose.Cells works as expected, but when it’s present NullReferenceException is thrown.

Now, we have to negotiate who is wrong. :slight_smile: As far as I can see from the ECMA-376 Part 1 there is nothing wrong with r:embed="". See this excerpt (52.3 KB), the above markup is not explicitly prohibited. Even more, on the page 4791 of the above specification there is such an example:

<p:blipFill>
  <a:blip r:embed="rId4" r:link="" />
  <a:stretch>
    <a:fillRect />
  </a:stretch>
</p:blipFill>

which is similar to our markup.

@volozyko,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-47608 - NullReferenceException on loading xlsx

@volozyko,

This is to inform you that we have fixed your issue now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@volozyko,

Please try our latest version/fix: Aspose.Cells for .NET v20.9.3 (attached)

Your issue should be fixed in it.

Let us know your feedback.
Aspose.Cells20.9.3 For .Net2_AuthenticodeSigned.Zip (5.4 MB)
Aspose.Cells20.9.3 For .Net4.0.Zip (5.4 MB)

@Amjad_Sahi, I confirm that the new Aspose.Cells 20.9.3 doesn’t throw when opening the attached document. The issue is fixed now.

@volozyko.

It is nice to know that you are up and running again. 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.

The issues you have found earlier (filed as CELLSNET-47608) have been fixed in Aspose.Cells for .NET v20.10. This message was posted using Bugs notification tool by Amjad_Sahi. You may also get the version @ Nuget repos. (NuGet Gallery | Aspose.Cells 20.10.0).