From: AA2e72E on
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


"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
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.
First  |  Prev  | 
Pages: 1 2
Prev: encoding
Next: Compiler Error when using VB Namespace