Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

GetSection returns null value #716

@xperiandri

Description

@xperiandri

I have config

{
  "CorsClients": "http://localhost:1089/; http://localhost:4200/",
  "Introspection": {
    "Authority": "https://localhost:44396/",
    "ClientId": "knowledge-base-api",
    "ClientSecret": "846B62D0-DEF9-4215-A99D-86E6B8DAB342"
  }
}

and class

internal class IntrospectionSettings
{
    internal Uri Authority { get; set; }
    internal string ClientId { get; set; }
    internal string ClientSecret { get; set; }
}

Configuration is passed in as follows

public void ConfigureServices(IServiceCollection services) =>
    services.AddAuthentication(OAuthIntrospectionDefaults.AuthenticationScheme)
                .AddCustomOAuthIntrospection(_configuration)

I tried to read it as

var settings = new IntrospectionSettings();
configuration.GetSection("Introspection").Bind(settings);

to make IntrospectionSettings as a struct

It does not work

Then I tried

var settings = configuration.GetSection("Introspection").Value;

It returns null

Also tried this

var settings = configuration.GetSection("Introspection")
               .Get<IntrospectionSettings>();

Questions:

  1. Why section cannot be a struct?
  2. How can Value property of IConfigurationSection be null but not JSON object?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions