i am facing Cannot serialize a generic type 'Microsoft.Practices.Prism.Commands.DelegateCommand`1[System.Object]'.
when Cloning.i am using the below method for cloning.
public static T TrycloneElement(T orig)
{
try
{
string s = XamlWriter.Save(orig);
StringReader stringReader = new StringReader(s);
XmlReader xmlReader = XmlTextReader.Create(stringReader, new XmlReaderSettings());
XmlReaderSettings sx = new XmlReaderSettings();
object x = XamlReader.Load(xmlReader);
return (T)x;
}
catch
{
return (T)((object)null);
}
}
please give me the solution
Thanks
Rajesh.
VulpesPosted Apr 30, 2013, 7:19 PM
The only solution I've seen is to create a non-generic class which inherits from the specific (i.e. closed constructed) generic class which you're trying to serialize.
The only code needed in the non-generic class will then be for a constructor which should do nothing except call the base class's constructor with the appropriate arguments.
You can then create an instance of the non-generic class, which to all intents and purposes will be the same as the specific generic class, and (hopefully) serialize that.