XML Document WriteTo Exception
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.
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
Can you provide a minimal repro of the issue, since it seems to depend on what is written to the outstream
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
What if you will do ?
TempBlob.CreateOutStream(OStream);
xmlDoc.WriteTo(OStream)
It may just be an encoding problem.
@SBalslev or @BazookaMusic, I believe the input-needed label can be removed again?
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.