There is an unclosed literal string. Line 1, position 12284

I have this class generated from a web-service:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "")]
public partial class RequestMessage 
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:ihe:iti:xds-b:2007", Order=0)]
    public Helper.RequestType Request;

    public RequestMessage() {

I'm trying to create an XmlDocument by:

XmlDocument xReq = new XmlDocument();

DataContractSerializer serializer = new DataContractSerializer(typeof(RequestMessage));
using (MemoryStream memStm = new MemoryStream())
    using (XmlWriter xw = XmlWriter.Create(memStm))
        //xnameSpace.Add("ns0", "urn:ihe:iti:xds-b:2007");
        serializer.WriteObject(xw, oReq);

        memStm.Position = 0;

But i'm getting an error: "There is an unclosed literal string. Line 1, position 12284." on "xReq.Load(memStm);" line.

I'm using UTF-8 encoding, but I've read that is the default of "XmlSerializerNamespaces"..

What can be the issue ?


You have to flush the XmlWriter before reading from it:

serializer.WriteObject(xw, oReq);
// Make sure all the XML has been written to the stream.
memStm.Position = 0;

Otherwise the last part of the serialized XML is not written to the stream and which in your case results in an opening quote without a closing quote.

In my case the program was still holding on to the XML file hence getting this error. Ending the program solved the problem.

Need Your Help

How to create splash screen as a Preloader in JavaFX standalone application?

javafx splash-screen preloader

I created a Preloader (based on the following tutorial) that should display a splash screen for the main application.

Parameterizing both data and object names using testNG and Data Providers

testng testng-dataprovider

I am trying to create a hybrid framework where I will be passing the object names and the corresponding values from an excel sheet. Here is what I want to do