locked
XmlSerializer does not like any data type

    Question

  • I am attempting to use the XmlSerializer to serialize my data. I have referenced System.Xml.Serialization, so that is not the problem. Regardless of what data type I use, whether it be one of my classes or something as simple as String, I get the following error:

    An exception of type 'System.Exception' occurred in mscorlib.dll but was not handled in user code

    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.

    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))

    So the problem is obviously not in any of my classes, because they are not used here. What is wrong with the above code, or where could the problem be? Thanks.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Wednesday, March 04, 2015 6:38 PM

Answers

  • "If you just need to serialize some string"

    That was not the point, I was simply using that as an example to show that even simple, built-in types gave the same error. I still don't have an explanation as to why this was happening, but apparently the next day it was working (even though I hadn't changed a single character in my code). Maybe Visual Studio 2013 hadn't been updating some of the files during compilation, or maybe it just needed some sleep. But either way, it is working fine now, so code that I expected to work is now working, so I guess I can say this task is complete for now.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Thursday, March 05, 2015 4:11 PM

All replies

  • 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.

    Thursday, March 05, 2015 8:38 AM
    Moderator
  • "If you just need to serialize some string"

    That was not the point, I was simply using that as an example to show that even simple, built-in types gave the same error. I still don't have an explanation as to why this was happening, but apparently the next day it was working (even though I hadn't changed a single character in my code). Maybe Visual Studio 2013 hadn't been updating some of the files during compilation, or maybe it just needed some sleep. But either way, it is working fine now, so code that I expected to work is now working, so I guess I can say this task is complete for now.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Thursday, March 05, 2015 4:11 PM