aaubry / YamlDotNet

YamlDotNet is a .NET library for YAML
MIT License
2.48k stars 466 forks source link

yaml.Documents[].RootNode is YamlScalarNode instead of YamlMappingNode in VS2022 console project #872

Closed RadovanPodhradskySk closed 7 months ago

RadovanPodhradskySk commented 7 months ago
  1. code created in VS2019 (and opened in VS 2022 too) in console application has YamlMappingNode type of yaml.Documents[0].RootNode of YAML document loaded by

using (StreamReader input = new StreamReader(_filePathAndName )) { // Load the stream var yaml = new YamlStream(); yaml.Load(input);

...

var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

...

  1. same file opened newly created in VS2022 console application

generate during load of same yaml file type cponversion exception on var mapping = ... line

I found, that there is difference in RootNode type between 1. and 2. (options above)

RootNode type is in VS2022 created console application YamlScalarNode

VS2022 console application has included YamlDotNet 13.7.1 VS2019 console application has included YamlDotNet 13.0.0

I tried to remove 13.7.1 version from VS2022 app and install 13.0.0, behaviour described above stay same

I can send you part of loaded yaml file, which has different RootNode type in VS2019 crreated application and VS 2022 creaded console application.

YAML file starts with:

Lines:

There are attached of screen snippets:

YamlRootNodeTypeException YamlRootNodeTypeMappingNode

EdwardCooke commented 7 months ago

In your top screen shot your casting to a YamlMappingNode before checking the type. In your second screenshot regardless of the type your still casting to YamlMappingNode. My suspicion is both throw an exception.

EdwardCooke commented 7 months ago

YamlMappingNode would come after the yamlscalar

RadovanPodhradskySk commented 7 months ago

1st picture was from VS2022 new console application 2nd picture was from VS2022 with opened console application created in VS2019

it was only example method in both solutions

I'm sending you short yaml file example (included in VS2022 solution archive), which has different AllNodes in console application created in VS 2022 and in VS 2019 console application opened in VS2022

I'm sending you archive with simple VS2022 WinForms application example and snippet of yamlNode.AllNodes View (Visualizer View) on Line30 in Form1.cs AllNodes usually shows whole yaml structure in Visual Studio Visualizer

There is no possibility to traverse from RootNode typed as YamlScalarNode to another node in structure of UnitDescTestShort.yaml file.

YamlLoadExampleVs2022.zip Vs2022_AllNodes_Visualizer

VS 2022 Professional version installed on my virtual Win10 is 17.6.4

Maybe my description is little bit more clear now.

EdwardCooke commented 7 months ago

Thanks, the version of Visual Studio shouldn't effect anything, it would be the version of .net that was being targeted by your project. I'll take a look at this tonight and let you know what I see.

EdwardCooke commented 7 months ago

In your zip file, In the ReadFile method you're creating a StringReader instead of a StreamReader.

RadovanPodhradskySk commented 7 months ago

Really, It was StringReader instead of StreamReader, I don't know how it was written, maybe with IntelliSense. I thought, that I copied these several lines from source file, where StreamWriter is used and behaviour is proper. Thanks for your attention to this my "issue". After using of StreamReader, AllNodes contains all yaml file nodes and RootNode type is YamlMappingNode. You are doing good job to create and support YamlDotNot over YAML standard. I use it in several company projects with very good experience.