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

Deserialization exception when running quick start example on Linux #950

Closed
karmeye opened this issue Aug 9, 2024 · 1 comment
Closed

Comments

@karmeye
Copy link

karmeye commented Aug 9, 2024

Describe the bug

When running the deserialization example from the README when published for Linux64 (in WSL) a get following exception:

Exception during deserialization
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser, Type, SerializerState, IValueDeserializer)
   at YamlDotNet.Serialization.ValueDeserializers.AliasValueDeserializer.DeserializeValue(IParser, Type, SerializerState, IValueDeserializer)
   at YamlDotNet.Serialization.Deserializer.Deserialize(IParser, Type)
   at YamlDotNet.Serialization.Deserializer.Deserialize[T](IParser)
   at YamlDotNet.Serialization.Deserializer.Deserialize[T](TextReader)
   at YamlDotNet.Serialization.Deserializer.Deserialize[T](String)
Unhandled exception. (Line: 2, Col: 1, Idx: 2) - (Line: 2, Col: 1, Idx: 2): Exception during deserialization

It works on Windows.

To Reproduce
Try to add the steps needed to reproduce the problem. Feel free to open a pull request with a failing test if that makes sense. Otherwise, at least provide some code and / or YAML that reproduce the issue.

static void TestYaml()
{
	var yml = @"
name: George Washington
age: 89
height_in_inches: 5.75
addresses:
  home:
    street: 400 Mockingbird Lane
    city: Louaryland
    state: Hawidaho
    zip: 99970
";

	try
	{
		var deserializer = new DeserializerBuilder()
	 .WithNamingConvention(UnderscoredNamingConvention.Instance)  // see height_in_inches in sample yml 
	 .Build();

		//yml contains a string containing your YAML
		var p = deserializer.Deserialize<Person>(yml); // Exception here
		var h = p.Addresses["home"];
		System.Console.WriteLine($"{p.Name} is {p.Age} years old and lives at {h.Street} in {h.City}, {h.State}.");
		// Output:
		// George Washington is 89 years old and lives at 400 Mockingbird Lane in Louaryland, Hawidaho.

	}
	catch (Exception ex)
	{
		Console.WriteLine($"{ex.Message}\n{ex.StackTrace}");
		throw;
	}
}

Then publish for
Screenshot 1

Then run. (I ran in WSL but I don't see why it shouldn't fail on the real thing).

Thanks

@EdwardCooke
Copy link
Collaborator

Because you're doing the produce single file/trimming you'll need to also reference the vecc.yamldotnet.staticanalyzers package and set that up. See #740 and #753.

Here's an example project as well

https://github.com/aaubry/YamlDotNet/tree/master/YamlDotNet.Core7AoTCompileTest

I'm going to go ahead and close this issue.

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