Thursday, March 5, 2015

XmlSerializer does not like any data type

Hi Nathan,


>>WinRT information: Error trying to serialize the value to be written to the application data store Additional information: Data of this type is not supported.


From the description, looks like you are tring to serialize a type which is not supported in WINRT, for example, if you want to serialize a Winrt control, it is inaccessible due to protection level.


>>This seems to happens no matter what type I use in the constructor, even the following gives the error: Dim xml As New XmlSerializer(GetType(String))


If you just need to serialize some string or custom class, you could try the following method:



private string SerializeToString(object obj)
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, obj);
return writer.ToString();
}
}



Class1:



public class Class1
{
public string Property1 { get; set; }
public Class1()
{
Property1 = "1";
}
}



How to use it:



string serializedData = SerializeToString(new Class1());





We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

Click HERE to participate the survey.


No comments:

Post a Comment