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

Reading YAML error: Cannot read the Value of an empty anchor #527

Closed
1 task done
vmelamed opened this issue Sep 18, 2023 · 2 comments
Closed
1 task done

Reading YAML error: Cannot read the Value of an empty anchor #527

vmelamed opened this issue Sep 18, 2023 · 2 comments
Labels
question Further information is requested

Comments

@vmelamed
Copy link

vmelamed commented Sep 18, 2023

Deserializing YAML throws InvalidOperationException with message 'Cannot read the Value of an empty anchor'

Hello,

Here is my code:

MyClass? ParseYaml(ArgumentResult _, TextReader reader)
{
        var yamlStream = new YamlStream();

        yamlStream.Load(reader);

        var doc = yamlStream.Documents[0].ToJsonDocument();
        return doc.Deserialize<MyClass>();
}

But from the last line, it throws an InvalidOperationException exception (see below) with the message 'Cannot read the Value of an empty anchor'. Am I missing something in my YAML (see below)?

Thank you
Val

System.InvalidOperationException
  HResult=0x80131509
  Message=Cannot read the Value of an empty anchor
  Source=YamlDotNet
  StackTrace:
   at YamlDotNet.Core.AnchorName.get_Value()
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer) in /_/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfoOfT.cs:line 229
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state) in /_/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectDefaultConverter.cs:line 340
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) in /_/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs:line 430
    ...
    [Call Stack Truncated]

  This exception was originally thrown at this call stack:
    YamlDotNet.Core.AnchorName.Value.get()
    System.Text.Json.Serialization.Metadata.JsonPropertyInfo<T>.GetMemberAndWriteJson(object, ref System.Text.Json.WriteStack, System.Text.Json.Utf8JsonWriter) in JsonPropertyInfoOfT.cs
    System.Text.Json.Serialization.Converters.ObjectDefaultConverter<T>.OnTryWrite(System.Text.Json.Utf8JsonWriter, T, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.WriteStack) in ObjectDefaultConverter.cs
    ...
    [Call Stack Truncated]

Here is the YAML:

description: Test CLI deployment
workload:
  serviceNamespace: Pool
  name: TestWorkload
  description: Example CLI workload
version: 0.0.0
packageFilename: TBD
selectors:
  os: windows
  dotnet-framework: net6.0
tolerations:
  - key: os
    value: windows
    effect: NoExecute
    operator: Equal
environmentVariables:
  Logging__LogLevel__Default: Information
  Logging__LogLevel__Microsoft: Warning
entryPoint: Delinea.EnginePool.TestWorkload.Console.exe
arguments: arg1 arg2
settingTemplates:
  - key: ID
    name: Unique identifier
    valueType: uuid
    description: Some unique identifier
  - key: dns
    name: DNS server address
    valueType: string
    description: Address of the DNS server
secretTemplates:
  - key: secret-key1
    name: Secret Key No1
    description: This is the secret 1
  - key: secret-key2
    name: Secret Key No2
    description: This is the secret 2
deprecated: false

Code of Conduct

  • I agree to follow this project's Code of Conduct
@vmelamed vmelamed added the documentation Improvements or additions to documentation label Sep 18, 2023
@gregsdennis
Copy link
Collaborator

This error doesn't involve my libraries. I think you'll need to take this to YamlDotNet, which is what I use to read the YAML.

@gregsdennis gregsdennis added question Further information is requested and removed documentation Improvements or additions to documentation labels Sep 18, 2023
@gregsdennis
Copy link
Collaborator

@vmelamed did you end up opening an issue with YamlDotNet?

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

No branches or pull requests

2 participants