Click here to Skip to main content
15,913,773 members
Home / Discussions / C#
   

C#

 
Questionenvt Pin
Member 125041034-May-16 23:52
Member 125041034-May-16 23:52 
AnswerRe: envt Pin
Eddy Vluggen5-May-16 0:06
professionalEddy Vluggen5-May-16 0:06 
AnswerRe: envt Pin
Pete O'Hanlon5-May-16 0:08
mvePete O'Hanlon5-May-16 0:08 
AnswerRe: envt Pin
Richard MacCutchan5-May-16 0:28
mveRichard MacCutchan5-May-16 0:28 
AnswerRe: envt Pin
Sascha Lefèvre5-May-16 0:44
professionalSascha Lefèvre5-May-16 0:44 
AnswerRe: envt Pin
Patrice T5-May-16 0:54
mvePatrice T5-May-16 0:54 
AnswerRe: envt Pin
koolprasad20035-May-16 18:58
professionalkoolprasad20035-May-16 18:58 
Questionc# Pin
Member 125041034-May-16 22:03
Member 125041034-May-16 22:03 
AnswerRe: c# Pin
Richard MacCutchan4-May-16 22:56
mveRichard MacCutchan4-May-16 22:56 
QuestionRe: c# Pin
Member 122800337-May-16 4:42
Member 122800337-May-16 4:42 
AnswerRe: c# Pin
Richard MacCutchan7-May-16 5:08
mveRichard MacCutchan7-May-16 5:08 
Questionc# Pin
Member 125041034-May-16 21:59
Member 125041034-May-16 21:59 
AnswerRe: c# Pin
Simon_Whale4-May-16 22:03
Simon_Whale4-May-16 22:03 
AnswerRe: c# Pin
OriginalGriff4-May-16 23:29
mveOriginalGriff4-May-16 23:29 
QuestionHow to deserialize an XML with information about a custom object, using DataContract? Pin
Member 125017234-May-16 18:21
Member 125017234-May-16 18:21 
0 down vote
favorite


I was able to serialize a List of objects (List) using this code:

C#
public static string Serialize(object obj)
{
    using (MemoryStream memoryStream = new MemoryStream())
    using (StreamReader reader = new StreamReader(memoryStream))
    {
        DataContractSerializer serializer = new DataContractSerializer(obj.GetType());
        serializer.WriteObject(memoryStream, obj);
        memoryStream.Position = 0;
        return reader.ReadToEnd();
    }
}


However, I'm not able to deserialize using this code:

C#
 public static object Deserialize(string xml, Type toType)
{
    using (Stream stream = new MemoryStream())
    {
        byte[] data = System.Text.Encoding.UTF8.GetBytes(xml);
        stream.Write(data, 0, data.Length);
        stream.Position = 0;
        DataContractSerializer deserializer = new DataContractSerializer(toType);
        return deserializer.ReadObject(stream);
    }
}


I'm not able to understand the problem. I'm using the last method by calling it with:

Deserialize(SerializedObject, List), but I'm getting an error saying List<FilesToProcess> is a type, which is not valid in the given context

Could anyone help? I'm a bit over my head with this.
AnswerRe: How to deserialize an XML with information about a custom object, using DataContract? Pin
Member 125017234-May-16 19:01
Member 125017234-May-16 19:01 
Questionproject Convert of Binary To Decimal Pin
Member 120777803-May-16 19:23
Member 120777803-May-16 19:23 
AnswerRe: project Convert of Binary To Decimal Pin
OriginalGriff3-May-16 19:43
mveOriginalGriff3-May-16 19:43 
AnswerRe: project Convert of Binary To Decimal Pin
Patrice T3-May-16 21:56
mvePatrice T3-May-16 21:56 
AnswerRe: project Convert of Binary To Decimal Pin
Pete O'Hanlon3-May-16 23:32
mvePete O'Hanlon3-May-16 23:32 
AnswerRe: project Convert of Binary To Decimal Pin
DaveyM694-May-16 4:21
professionalDaveyM694-May-16 4:21 
Questioninterface inherits from interface, method over-ridden: my brain is stuck Pin
BillWoodruff3-May-16 7:24
professionalBillWoodruff3-May-16 7:24 
AnswerRe: interface inherits from interface, method over-ridden: my brain is stuck Pin
Sascha Lefèvre3-May-16 10:20
professionalSascha Lefèvre3-May-16 10:20 
GeneralRe: interface inherits from interface, method over-ridden: my brain is stuck Pin
BillWoodruff4-May-16 2:55
professionalBillWoodruff4-May-16 2:55 
GeneralRe: interface inherits from interface, method over-ridden: my brain is stuck Pin
Sascha Lefèvre4-May-16 4:45
professionalSascha Lefèvre4-May-16 4:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.