title: Serialize a Dictionary<string, object> that contains a List<string>?
body: <p>I've found a Serializeable Dictionary which works quite fine: <a href="http://www.jankowskimichal.pl/en/2010/10/serializabledictionary/" rel="nofollow">http://www.jankowskimichal.pl/en/2010/10/serializabledictionary/</a></p>
  
  <p>But I'm getting an exception whenever one of the objects in the dictionary is simply a list of strings.  .NET is telling me it can't serialize it:</p>
  
  <pre><code>Serialize 'C:\bin\Debug\Settings\Default.xml' : System.InvalidOperationException: There was an error generating the XML document. ---&gt; System.InvalidOperationException: There was an error generating the XML document. ---&gt; System.InvalidOperationException: The type System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] may not be used in this context.
     at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
     at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterObject.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
     at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterObject.Write2_anyType(Object o)
     --- End of inner exception stack trace ---
     at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
     at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o)
     at ShadowBot.Classes.SerializableDictionary`2.WriteXml(XmlWriter writer) in c:\Classes\SerializableDictionary.cs:line 114
     at System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)
     at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterShadowSettings.Write2_ShadowSettings(String n, String ns, ShadowSettings o, Boolean isNullable, Boolean needType)
     at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterShadowSettings.Write3_ShadowSettings(Object o)
     --- End of inner exception stack trace ---
     at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
     at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object o, XmlSerializerNamespaces namespaces)
     at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object o)
     at Classes.XmlSerializer.Serialize(String Path, Object Object) in c:\Classes\XmlSerializer.cs:line 29
  </code></pre>
  
  <p>Is this even possible? I'd like this capability and just assumed you could nest objects like this.  If this isn't possible, is there a way I can just write the dictionary to disk (doesn't have to be XML) and then re-load it without me having to write custom wrappers for this? I was originally a mac developer and this type of serialization was quite simple, so maybe I'm missing something on .NET.</p>
  
  <p>Edit: When trying odyss' example i get: </p>
  
  <pre><code>System.Runtime.Serialization.SerializationException: Type 'System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
  </code></pre>