So I need to serialize a generic dictionary like Dictionary<long, List<MyClass>>
. I need to serialize it to store it in the ViewState of an ASP.Net application.
I found an example of using TypeConverter
to convert my class to a string to be serialized, but I get an error message saying MyClass is not marked as serializable
.
Here is the code for my class..
[TypeConverter (typeof(MyClass_Converter))]
public class MyClass
{
// some properties
}
public class MyClass_Converter : System.ComponentModel.TypeConverter
{
public override bool CanConvertTo(...)
{
// code
}
// CanConvertFrom, ConvertFrom, ConvertTo methods
}
Then when I want to serialize it, I am using this code...
LosFormatter los = new LosFormatter();
StringWriter sw = new StringWriter();
los.Serialize(sw, hiddenData);
String resultSt = sw.GetStringBuilder().ToString();
ViewState["HiddenData"] = resultSt;
Am I doing something wrong?