Solved C# to xml error Dictionary

xandeturf

Moderator
Moderator
Nov 4, 2015
132
25
28
35
hello, i want to use :
C#:
Helper.ObjectToXML<SerializableDictionary<ulong, Dictionary<string, string>>>(listcheck, RustPPModule.GetAbsoluteFilePath("listcheck.xml"));
It's possible?

This error appears:
C#:
 System.NotSupportedException: The type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyT
oken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] is not supported because it imple
ments IDictionary.
  at System.Xml.Serialization.TypeData.get_ListItemType () [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.TypeData.get_ListItemTypeData () [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.TypeData..ctor (System.Type type, System.String elementName, Boolean isPrimitive, System.Xml.Serialization.TypeData mapp
edType, System.Xml.Schema.XmlSchemaPatternFacet facet) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.TypeData..ctor (System.Type type, System.String elementName, Boolean isPrimitive) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.TypeTranslator.GetTypeData (System.Type runtimeType, System.String xmlDataType) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.TypeTranslator.GetTypeData (System.Type type) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.TypeTranslator.GetTypeData (System.Type runtimeType, System.String xmlDataType) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.TypeTranslator.GetTypeData (System.Type type) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String
defaultNamespace) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.Xml.Serialization.XmlAttributeOverrides overrides, System.Type[] extraType
s, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type) [0x00000] in <filename unknown>:0
  at RustPP.Helper.ObjectToXML[SerializableDictionary`2] (Fougerite.SerializableDictionary`2 obj, System.String path) [0x00000] in <filename unknown>:
0
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
I have no idea, but I guess XML does not support dictionaries?
It should work for a dictionary, Maybe you need to serialize it?
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]is not supported because it imple
ments IDictionary.

Try with IDictionary instead of Dictionary i guess.
 

xandeturf

Moderator
Moderator
Nov 4, 2015
132
25
28
35
thanks, It worked.
C#:
Helper.ObjectToXML<SerializableDictionary<ulong, SerializableDictionary<string, string>>>(listcheck, RustPPModule.GetAbsoluteFilePath("listcheck.xml"));