ExportXML with XML Map throwing NullReferenceException

Hello,

I am trying to export data from Excel as XML using the Workbook.ExportXml Method . With some files, this method throws a NullReferenceException, even though the file does contain a valid XML Map that can be used from Excel to correctly export data in XML format.

This is the code used:

class Program
{
    private const string ResourcesFolder = "Resources";
    private const string FileName = "Example.xlsx";
    private const string xsdFilename = "xmlMaps.xsd";
    private const string xmlFilename = "extractedXML.xml";

    static void Main(string[] args)
    {
        string sourceDir = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), ResourcesFolder);
        string path = Path.Combine(sourceDir, FileName);
        string xmlPath = Path.Combine(sourceDir, xmlFilename);

        GetXmlMapFile(path, xmlPath);

        Console.WriteLine("XML extracted to: " + xmlPath);
        Console.ReadLine();
    }

    static void GetXmlMapFile(string filePath, string destination)
    {
        // Load sample Excel file having XML Map
        Workbook wb = new Workbook(filePath);

        if (wb.Worksheets.XmlMaps.Count >= 1)
        {
            XmlMap map = wb.Worksheets.XmlMaps[0];
            wb.ExportXml(map.Name, destination);
        }
    }
}

You can see that the variable “map” is not null:
image.png (41.0 KB)

The Excel file: Example.zip (7.9 KB)

This issues looks like the same as this one: ExportXML using XML Map is throwing error

Best Regards

@niciuffo,

Please notice, I am able to reproduce the issue as you mentioned by using your template file and sample code. I found that ExportXml with XML Map is throwing “NullReferenceException”. I have logged a ticket with an id “CELLSNET-49497” for your issue. We will look into it soon.

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

1 Like

@niciuffo,

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.

1 Like

@Amjad_Sahi

Thank you for the quick status update.

Since this is our first time working with your libraries, could you give us an estimate on when the fix will be available for us to test? Will it be integrated in the next release (is there a schedule for that?) or can we expect it sooner?

Best Regards,
Nicolas

@nicolas.realini,

You may expect the fix in a couple of days. We share a fix in the forums for the users once it passes QA and we have included other enhancements, etc.

Yes, sure, our official releases include all the previous fixes and other enhancements. Please note, we publish official release of the product (in Downloads and Nuget repos.) once in a month. Our next official release of the API, i.e., Aspose.Cells for .NET v21.11 is expected around mid November, 2021. You will also be notified once the next release is published.

@Amjad_Sahi

Thank you for the information. We very much look forward to test the fix once it has passed your internal QA tests.

@niciuffo @nicolas.realini

The issue is fixed in v21.10.1.
Aspose.Cells21.10.1 For .Net2_AuthenticodeSigned.Zip (5.6 MB)
Aspose.Cells21.10.1 For .Net4.0.Zip (5.6 MB)
Aspose.Cells21.10.1 For .NetStandard20.Zip (5.6 MB)

@Peyton.Xu @Amjad_Sahi

Thank you for the hotfix. We could test this successfully with the sample Excel file.

Unfortunately, we could still reproduce the issue with a more complex Excel file, which I am attaching here: TestExcel_2.zip (115.3 KB)

The error message is exactly the same. Could you check to see if you can also reproduce the issue?

Best Regards,
Nicolas

@nicolas.realini,

You are right. I found it still produces the same issue with your new file as I tested. I have reopened your issue again. We will be looking into your issue and get back to you soon.

1 Like

@nicolas.realini,

We found the XmlMap definition(schema) in the new source file “TestExcel_2.xlsx” is quite different and more complex. We decided to create new engine to parse such schemas. We have logged a separate ticket with an id “CELLSNET-49595” for this issue. This will take significantly more time. Once we have an update on it, we will let you know here.

PS. we closed the older/existing ticket “CELLSNET-49497” and will be working on the new ticket (CELLSNET-49595).

@Amjad_Sahi

Thank you for your message.

We are planning a software release this November that would include this feature.

  1. Do you know what the main cause of the bug is, and is there be a workaround that we can apply to these kinds of XML maps to avoid it?

  2. Would you be able to provide an estimate for the delivery of this fix?

Best Regards,
Nicolas

We have not evaluated your issue thoroughly, so might not comment or provide eta on it.
Also, since we will be creating new engine to parse complex schemas, so this task might take some time. We will get back to you and try to provide an estimate (if possible).

@Amjad_Sahi

Thank you. We would be grateful for an estimation to help with our release scheduling, if possible.

Best Regards,
Nicolas

@nicolas.realini,

Yes, sure. Hopefully we will get back to you in the next early with new updates/ETA on it.

@nicolas.realini

When export to xml, we need to know the structure of XmlMap which is defined by schema(You can open the source xlsx file by a zip tool and check ‘xl/xmlMaps.xml’ in zip). As the screenshot schema_2.png (13.4 KB) highlighted, the element ‘/CISReporting/CISRecordInfo’ is defined outside by type="CISRecordType", currently we have issues while parsing it.

We will try to provide a fix in this week to fix the NullReferenceException first.

1 Like

@nicolas.realini

The issue CELLSNET-49595 is fixed in the fix v21.10.2.
Aspose.Cells21.10.2 For .Net2_AuthenticodeSigned.Zip (5.6 MB)
Aspose.Cells21.10.2 For .Net4.0.Zip (5.6 MB)
Aspose.Cells21.10.2 For .NetStandard20.Zip (5.6 MB)

@Peyton.Xu @Amjad_Sahi

We have installed this new version and can confirm that the issue with this specific Excel file has been fixed. Thank you! We will let you know if we find anything else during our testing with other files.

Best Regards,
Nicolas

@nicolas.realini,

It is nice to know that the fix works for your needs well. And, sure, take your time to evaluate the new fix and in the event of further queries or issue, feel free to write us back.

The issues you have found earlier (filed as CELLSNET-49497,CELLSNET-49595) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao

Hello @Amjad_Sahi,

The same issue seems to be occurring again with the following Excel file: Aspose.Cells_ExportXML_NullReferenceException.zip (498.8 KB)

The code used to extract the XML map is the same as previously reported.

We have tested this with both Aspose.Cells 21.10.2, as well as the latest version 22.1.0. The XML map is exported correctly from Excel itself.

Could you check this and let us know if you can also reproduce the issue?

Best Regards,
Nicolas