I have been struggling with something on and off for about a week now.
I am creating a program that can take a .yaml and parse it into an object for manipulation and output. The issue I have is an error with the YAMLDotNet package, When it gets to the deserialization instruction it throws an exception as follows:
An unhandled exception of type 'YamlDotNet.Core.YamlException' occurred in YamlDotNet.dll
Additional information: (Line: 5, Col: 13, Idx: 54) - (Line: 5, Col: 22, Idx: 63): Exception during deserialization
I realise it is associated with the character " ' " and I believe it is an issue with not assigning types. I have had a look around and tried a few solutions as you will see with some commented code but no luck. Can someone please point me in the right direction? I would also greatly appreciate any relevant reading material about serialization and deserialization around YAML.
Disclaimer: I am a semi-educated non published coder just coding for my own enjoyment/purposes. This is my first attempt at getting public help on a coding problem so If i have not provided enough information or incorrect information please let me know so I can correct it.
Here is a sample of the YAML:
0:
groupID: 0
mass: 1.0
name:
de: '#System'
en: '#System'
fr: '#Système'
ja: '#システム'
ru: '#Система'
zh: '#星系'
portionSize: 1
published: false
2:
groupID: 2
name:
de: Corporation
en: Corporation
fr: Corporation
ja: コーポレーション
ru: Corporation
zh: 军团
portionSize: 1
published: false
3:
groupID: 3
name:
de: Region
en: Region
fr: Région
ja: リージョン
ru: Region
zh: 星域
portionSize: 1
published: false
volume: 1.0
4:
groupID: 4
name:
de: Constellation
en: Constellation
fr: Constellation
ja: コンステレーション
ru: Constellation
zh: 星座
portionSize: 1
published: false
volume: 1.0
5:
groupID: 5
name:
de: Solar System
en: Solar System
fr: Système solaire
ja: ソーラーシステム
ru: Solar System
zh: 星系
portionSize: 1
published: false
radius: 5000000000000.0
volume: 1.0
6:
description:
de: 'Dieser Hauptreihenstern gehört einer Klasse an, die sich oft durch eine
gelbe oder gelblich-orange Farbe auszeichnet und über den gewaltigen Wasserstofffusionsprozess
im Herzen des Sterns eine enorme Menge Energie erzeugt und ausstrahlt.
Im Orbit dieser Planeten können sowohl terrestrische Planeten als auch
Gasriesen in unterschiedlicher Anzahl gefunden werden, von denen sich
einer oder mehrere in der bewohnbaren Zone befindet.'
en: "A main-sequence stellar body of a class that is often yellow or yellow-orange
in hue, generating and emitting energy from the vast hydrogen fusion process
within the heart of the star.\r\n\r\nVarious numbers of planets of the
terrestrial and gas giant types are found around these stars and the habitable
zones often contain one or more planets."
fr: Communément jaunes ou jaune orangé, ces étoiles de la séquence principale
génèrent et émettent de l'énergie par fusion des noyaux d'hydrogène emprisonnés
dans le cœur. Leur écosphère stellaire engendre la formation de planètes
géantes de type terrestre ou gazeux, parmi lesquelles quelques spécimens
gravitent souvent en zone habitable.
ru: 'Звезда главной последовательности, желтого или желто-оранжевого цвета,
генерирует и излучает энергию в ходе мощного процесса водородного термоядерного
синтеза, идущего в центре звезды.
Вокруг этих звезд могут находиться планетные системы, состоящие из планет
земного типа и газовых гигантов; в обитаемой зоне часто находится как
минимум одна планета.'
graphicID: 21457
groupID: 6
mass: 1000000000000000000
Here are my object classes:
class YAMLTypeIDs
{
public Dictionary<int,YAMLtempItem> YAMLTypeids { get; set; }
}
class YAMLtempItem
{
public decimal basePrice { get; set; }
public Dictionary<string, YAMLItemDescription> description { set; get; }
public int groupID { get; set; }
public int iconID { get; set; }
public int marketGroupID{ get; set; }
public string mass { get; set; }
public Dictionary<string, YAMLItemName> name { set; get; }
public int portionSize { get; set; }
public bool published { get; set; }
public decimal volume { get; set; }
}
class YAMLItemDescription
{
public string de { get; set; }
public string en { get; set; }
public string fr { get; set; }
public string ja { get; set; }
public string ru { get; set; }
public string zh { get; set; }
}
class YAMLItemName
{
public string de { get; set; }
public string en { get; set; }
public string fr { get; set; }
public string ja { get; set; }
public string ru { get; set; }
public string zh { get; set; }
}
and here is my instruction code:
input = System.IO.File.ReadAllText(@"sde/fsd/typeIDs.yaml");
var deserializer = new Deserializer();
var strtemp = new StringReader(input);
var itemTypes = deserializer.Deserialize<Dictionary<int, YAMLtempItem>>(strtemp);
/*deserializer.RegisterTagMapping("de", typeof(string));
deserializer.RegisterTagMapping("en", typeof(string));
deserializer.RegisterTagMapping("fr", typeof(string));
deserializer.RegisterTagMapping("ja", typeof(string));
deserializer.RegisterTagMapping("ru", typeof(string));
deserializer.RegisterTagMapping("zh", typeof(string));
deserializer.RegisterTagMapping("name", typeof(YAMLItemName));
deserializer.RegisterTagMapping("groupID", typeof(int));
deserializer.RegisterTagMapping("portionSize", typeof(int));
deserializer.RegisterTagMapping("published", typeof(bool));
deserializer.RegisterTagMapping("volume", typeof(decimal));
deserializer.RegisterTagMapping("description", typeof(YAMLItemDescription));
deserializer.RegisterTagMapping("graphicID", typeof(int));
deserializer.RegisterTagMapping("mass", typeof(string));*/