AL icon indicating copy to clipboard operation
AL copied to clipboard

XML Document WriteTo Exception

Open MarcE85 opened this issue 5 months ago • 5 comments

1. Describe the bug Writing an XmlDocument to an OutStream was working perfectly fine, but it has now started to randomly throw an exception.

2. To Reproduce Steps to reproduce the behavior:

TempBlob.CreateOutStream(lOutStream, TextEncoding::UTF8);
pXMLDocument.WriteTo(lOutStream);

3. Expected behavior XML is written to the outstream

4. Actual behavior Exception of type 'Microsoft.Dynamics.Nav.Types.Exceptions.NavNCLArgumentException' was thrown. Image

5. Versions:

  • AL Language:
  • Visual Studio Code: 1.101.2
  • Business Central: 26.3
  • List of Visual Studio Code extensions that you have installed: AL Code
  • Operating System:
    • [ X] Windows
    • [ ] Linux
    • [ ] MacOS

MarcE85 avatar Jul 30 '25 08:07 MarcE85

Can you provide a minimal repro of the issue, since it seems to depend on what is written to the outstream

BazookaMusic avatar Aug 05 '25 07:08 BazookaMusic

Hi,

here is an example:

local procedure GenXMLTest()
    var
        xmlDoc: XmlDocument;
        TempBlob: Codeunit "Temp Blob";
        OStream: OutStream;
        Istream: Instream;
        XmlDec: XmlDeclaration;
        xmlEle: XmlElement;
    begin
        XmlDec := XmlDeclaration.Create('1.0', 'utf-8', 'yes');
        xmlDoc := XmlDocument.Create();
        xmlDoc.SetDeclaration(XmlDec);
        xmlEle:= XmlElement.Create('root');
        xmlEle.Add('texttext');

        xmlDoc.Add(xmlEle);

        TempBlob.CreateOutStream(OStream, TextEncoding::UTF8);
        xmlDoc.WriteTo(OStream); <-- Error
end;

I was able to resolve the error by removing a character that isn't allowed in XML 1.0.

From my point of view, it's fine that an error occurs, but it might be helpful if the reason for the error were made more visible.

Regards Marc

MarcE85 avatar Aug 07 '25 08:08 MarcE85

What if you will do ?

TempBlob.CreateOutStream(OStream);
xmlDoc.WriteTo(OStream)

It may just be an encoding problem.

Drakonian avatar Aug 08 '25 12:08 Drakonian

@SBalslev or @BazookaMusic, I believe the input-needed label can be removed again?

NKarolak avatar Aug 11 '25 06:08 NKarolak

What if you will do ?

TempBlob.CreateOutStream(OStream);
xmlDoc.WriteTo(OStream)

It may just be an encoding problem.

If I do that without adding the special character that isn’t allowed, it works.

MarcE85 avatar Aug 12 '25 08:08 MarcE85