aaubry / YamlDotNet

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

Problem Deserializing a list of player #875

Closed robinmoon2 closed 7 months ago

robinmoon2 commented 7 months ago

Hello, I have a problem. I have a code that can write this kind of YAML file :

I use the serializer to write the YAML file and it works pretty well. But when I need to read it with the deserializer and put it in a list of players it doesn't work and I have the error message following : Unhandled exception. (Line: 1, Col: 3, Idx: 2) - (Line: 1, Col: 3, Idx: 2): Exception during deserialization.

I put the 2 function below, if someone have the solution it will really help me out.

image

EdwardCooke commented 7 months ago

Can you your entire player class? There should also be more details on that exception as well.

robinmoon2 commented 7 months ago

So this is the player class : image

Then I built the PlayerList class : image

And this is where I call the function to Read and Write on the YAML File.

The function Writing works perfectly but not the reading one.

What do you mean by "Can you your entire player class" ?

I don't find any more details about this exception on the repo.

EdwardCooke commented 7 months ago

You need a parameterless constructor on your player class. Add that in there and it should work.

EdwardCooke commented 7 months ago

Did that resolve the problem?

robinmoon2 commented 7 months ago

Yes this solves the problem at perfection.

Thanks you a lot :)