✅ .NET Worker service doesn't load appsettings.json into a class
Hello,
I am trying to load configuration values into a class or record, but it doesn't work. The properties remain
null
.
I do the following:
Loading config values this way works in a Web API project, but I don't understand why it wouldn't in an other type of project.
I've also added the DnsRecords
configuration to appsettings.json
and appsetting.Development.json
, but the outcome was the same.8 Replies
what does your Program.cs look like? is it using Host.CreateDefaultBuilder()?
is builder.Configuration.GetSection returning the actual 0.0.0.0 value?
also, is your appsettings.json set to copy on build?
No, it's using the
Host.CreateApplicationBuilder()
No, there is no extra configuration. Everything is how the default Program.cs
was generatedwhat i mean is, your appsettings.json should be set to copy on build
is it present in the /bin/ folder when you compile your app?
this all looks fine, so i am wondering if the appsettings.json is missing somehow
no, because also access other configs before build, like this
builder.Configuration["MessageBroker:Host"]
and it gets the values
so the appsettings,json must have been copied
wow..... I am an idiot.
There is an extra :
in the config name....
Everything works fine :))haha
classic
well, glad you found it 🙂
Thanks for helping me
$close
If you have no further questions, please use /close to mark the forum thread as answered