.net - DataContractSerializer, KnownType and inheritance -
I have read many articles about known types and I should consider my example that work should be done. But this is not me getting the following exception on deserialization and I do not understand why:
Error in line 1 position 2. Except 'A' from the namespace, "name", "namespace".
using the system; Use the system. time. Timeliness; Using System.Xml; Using System.IO; Namespace Console Application 2 [[Detacontrkt] [known type (Taipf (c)) class A {} [Detacontrkt] Class C: A {} class Program {[static void main (String] ARG) {A a = new C () ; String data; Var Serializer = New Data Contrast Cylizer (a.GetType ()); (Var sw = new stringwriter ()) using ({var xw = new XmlTextWriter (sw)) serializer.WriteObject (xw, A); Data = sw.ToString (); } Serializer = New Data Contributorizer (Typef (A)); (Var sr = new string reader (using data)) (var xr = new XmlTextReader (sr)) a = (A) serializer.ReadObject (xr); }}}
What am I missing?
Change the way you create the serializer:
Var serializer = new datasetricetricularizer (typef (A));
instead of a.GetType ();
This works which XML is generated is different - something like this:
& lt; C & gt; ...
And now it is:
& lt; A i: type = "c" & gt; ...
Comments
Post a Comment