Configuration.GetSection always returns null

前端 未结 9 1201
借酒劲吻你
借酒劲吻你 2020-12-16 09:01

Every time I call Configuration.GetSection, the Value property of the returned object is always null.

My Startup constructor

9条回答
  •  别那么骄傲
    2020-12-16 09:38

    According to the Microsoft Docs: "When GetSection returns a matching section, Value isn't populated. A Key and Path are returned when the section exists."

    If you want to see the values of that section you will need to call the GetChildren() method: Configuration.GetSection("SqliteSettings").GetChildren();

    Or you can use: Configuration.GetSection("SqliteSettings").Get(). The JSON does not need to have the same amount of properties to match. Unmatched nullable properties will be set to null and non-nullable unmatched properties will be set to their default value (e.g. int will be set to 0).

提交回复
热议问题