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

assets:precompile tries to compile a sass partial when it shouldn't

ruby-on-rails sass asset-pipeline

Any idea why Rails' assets:precompile would try to compile a sass partial _accounts.css.sass when it's not listed in my precompile list?

How to access Web.config from a referenced assembly? assemblies web-config

I need to access a web application's web.config from a referenced assembly. I need to get the file's path or the configuration object. I can't do this using System.Reflection.Assembly.GetEntryAssem...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.