Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RadovanPodhradskySk opened this issue Nov 19, 2023 · 6 comments

Comments

@RadovanPodhradskySk
Copy link

  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:

  • UnitLine: LineName
    Branches:
    • UnitBranch: BranchName
      Models:
      • UnitModel: ModelName
        SerialNumber: 0000000000003
        Unit Revision: 1
        Specification: SpecName

There are attached of screen snippets:

  • with exception shown in VS2022 created new console application solution
  • statement with YamlMappingNode type tested during same file load in VS 2019 console application opened in VS 2022.

YamlRootNodeTypeException
YamlRootNodeTypeMappingNode

@EdwardCooke
Copy link
Collaborator

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
Copy link
Collaborator

YamlMappingNode would come after the yamlscalar

@RadovanPodhradskySk
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Collaborator

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

@RadovanPodhradskySk
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants