Prev: encoding
Next: Compiler Error when using VB Namespace
From: AA2e72E on 19 Mar 2010 07:39 I had already tried your suggestion ........ XmlSerializer ser = new XmlSerializer(myFile.GetType()); MemoryStream ms = new MemoryStream(); ser.Serialize(ms, myFile); ........... but without success; I encounter <>f__AnonymousType0`2[System.String,System.Int32] cannot be serialized because it does not have a parameterless constructor.
From: Family Tree Mike on 19 Mar 2010 08:36 "AA2e72E" wrote: > I had already tried your suggestion ........ > > XmlSerializer ser = new XmlSerializer(myFile.GetType()); > MemoryStream ms = new MemoryStream(); > ser.Serialize(ms, myFile); > > .......... but without success; I encounter > > <>f__AnonymousType0`2[System.String,System.Int32] cannot be serialized > because it does not have a parameterless constructor. Ah, yes... That does make sense. I think reflection as Alberto replied earlier would work. Mike
From: Mr. Arnold on 19 Mar 2010 08:37
AA2e72E wrote: > I had already tried your suggestion ........ > > XmlSerializer ser = new XmlSerializer(myFile.GetType()); > MemoryStream ms = new MemoryStream(); > ser.Serialize(ms, myFile); > > .......... but without success; I encounter > > <>f__AnonymousType0`2[System.String,System.Int32] cannot be serialized > because it does not have a parameterless constructor. You would need to make a new object call it MyObject and serialize that. public class MyObject { public string FullName {get; set;} public int FileLength {get; set;} } var myobject = (from file in fileList // Most recent file orderby file.CreationTime descending select new MyObject{ FullName = file.FullName, FileLength = file.Length}).First(); You should be able to serialize MyObject. |