InvalidOperationException while SOAP serialization of complex type?

Use XmlWriter instead of StringWriter and do a writer. WriteStartElement("root").

Use XmlWriter instead of StringWriter and do a writer. WriteStartElement("root"); This will work: Stream s = new MemoryStream(); XmlWriter writer = new XmlTextWriter(s, Encoding. UTF8); SoapReflectionImporter importer = new SoapReflectionImporter(); XmlTypeMapping map = importer.

ImportTypeMapping(typeof(A)); XmlSerializer serializer = new XmlSerializer(map); writer. WriteStartElement("root"); serializer. Serialize(writer, new A()); StreamReader sr = new StreamReader(s); string data = sr.ReadToEnd().

Thanks, this helps. But I've got another problem, this time with deserization. If I override method GetHashCode() in class A and try to access property BB, then NullReferenceException appears during Deserialization.

Somehow property BB equals 0, but it shouldn't. – Dmitry Lobanov Jun 18 '09 at 9:58 Can you post your deserialization code? I'll hav a look – Rashmi Pandit Jun 18 '09 at 12:09 Well, I localized the problem.

Deserializator behaves itself pretty strange, it creates new instance of deserialized class (by invoking default constructor), after this it manually sets all fields and properties to their default values. That mean that it sets reference-type properties to null. And then deserializator invokes methods like GetHashCode() and Equals().

But my own realizations of these methods "know" that properties never will be null. That caused the exception. I just changed code in GetHashCode() and Equals(), now they "know" that properties can be null.

Thanks for help! – Dmitry Lobanov Jun 19 '09 at 2:19 Okay ... great! Thanks for the info :) – Rashmi Pandit Jun 19 '09 at 3:15 The XML Serializer pays no attention to a non-default constructor, not to indexers, operators, or much of anything else.It's basically meant to serialize the public read/write properties of a class.

– John Saunders Jun 19 '09 at 3:21.

Just a note, The upper example will not work if the position of the stream is not set to the start of the stream. Like so: Stream s = new MemoryStream(); XmlWriter writer = new XmlTextWriter(s, Encoding. UTF8); SoapReflectionImporter importer = new SoapReflectionImporter(); XmlTypeMapping map = importer.

ImportTypeMapping(typeof(A)); XmlSerializer serializer = new XmlSerializer(map); writer. WriteStartElement("root"); serializer. Serialize(writer, new A()); s.

Position = 0; StreamReader sr = new StreamReader(s); string data = sr.ReadToEnd().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions