YamlDotNet 的琐碎反序列化失败

Ral*_*lfW 4 yamldotnet

这可能会出什么问题:

    public void Main()
    {
        var input = new StringReader(Document);

        var deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention());
        var p = deserializer.Deserialize<Person>(input);

        Console.WriteLine(p.Name);
    }

    public class Person
    {
        public string Name {get;set;}
    }

    private const string Document = @"Name: Peter";
Run Code Online (Sandbox Code Playgroud)

抛出序列化异常:

Property 'Name' not found on type 'YamlDotNet.Samples.DeserializeObjectGraph+Person'
Run Code Online (Sandbox Code Playgroud)

如果我首先使用序列化程序序列化 Person 对象,也会发生同样的情况。

虽然反序列化的在线示例工作得很好 - 这个简单的代码没有。我错过了什么?这一定是一个愚蠢的小细节。(但它发生在我尝试过的其他数据结构之前。)

Ral*_*lfW 6

看起来,问题出在namingConvention 参数上。如果我不将它设置为 CamelCaseNamingConvention 的实例,一切都很好。

不幸的是,“规范”示例(https://dotnetfiddle.net/HD2JXM)使用了它,因此表明它很重要。