TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mr Pogan
NA
3
740
How to deserialize an XML with information about a custom ob
May 5 2016 12:34 AM
I was able to serialize a List of objects (List) using this code:<br /><br />Hide Copy Code<br /><br /><strong>public static string Serialize(object obj)<br />{<br /> using (MemoryStream memoryStream = new MemoryStream())<br /> using (StreamReader reader = new StreamReader(memoryStream))<br /> {<br /> DataContractSerializer serializer = new DataContractSerializer(obj.GetType());<br /> serializer.WriteObject(memoryStream, obj);<br /> memoryStream.Position = 0;<br /> return reader.ReadToEnd();<br /> }<br />}</strong><br /><br /><br />However, I'm not able to deserialize using this code:<br /><br />Hide Copy Code<br /><br /> <strong>public static object Deserialize(string xml, Type toType)<br />{<br /> using (Stream stream = new MemoryStream())<br /> {<br /> byte[] data = System.Text.Encoding.UTF8.GetBytes(xml);<br /> stream.Write(data, 0, data.Length);<br /> stream.Position = 0;<br /> DataContractSerializer deserializer = new DataContractSerializer(toType);<br /> return deserializer.ReadObject(stream);<br /> }<br />}</strong><br /><br /><br />I'm not able to understand the problem. I'm using the last method by calling it with:<br /><br />Deserialize(SerializedObject, List), but I'm getting an error saying <strong>List is a type, which is not valid in the given context</strong><br /><br />Could anyone help? I'm a bit over my head with this.
Reply
Answers (
1
)
WCF - Class/Channel/Client
Restful WCF Service with 2 Parameters