Serialization of nested collections

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric




While serializing of your type you may get following exception:

"Unable to generate a temporary class (result=1).
error CS0136: A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else

In my specific case following type have been used: StorageClone which implements IEnumerable of type StorageStackClone which is also enumerable:




Following code snippet shows the code used to serialize types shown above:

  StorageClone st = new StorageClone();
System.IO.StreamWriter sw1 = new System.IO.StreamWriter("a.txt");
XmlSerializer dbSer1 = new XmlSerializer(typeof(StorageClone));
dbSer1.Serialize(sw1, st);

After executing of this code the exception is thrown. To solve the problem try to avoid nested collections. Following example shows one possible solution:



Posted Feb 22 2008, 04:53 PM by Damir Dobric is a .Net Community Blog powered by daenet GmbH.