Giter Club home page Giter Club logo

Comments (5)

Tratcher avatar Tratcher commented on August 22, 2024

Can you show appsettings.json and the related environment variables?

from hosting.

Tratcher avatar Tratcher commented on August 22, 2024

Also, try making appsettings.json optional: false to make sure the file is being found correctly.

from hosting.

imxavi avatar imxavi commented on August 22, 2024

Hi, sorry let me explain better.
I did 2 scenarios:
A)
using just CreateDefaultBuilder without UseConfiguration
var hostBuilder = WebHost.CreateDefaultBuilder(args);

var settingName = "SHUTDOWNTIMEOUTSECONDS";
var settingStrShutdownTimeout = hostBuilder.GetSetting(settingName);

  • launchSettings.json:
    SHUTDOWNTIMEOUTSECONDS not added to env vars
  • appsettings.json:
    {
    "SHUTDOWNTIMEOUTSECONDS": 50
    }
    like this settingStrShutdownTimeout is null.
    Could it be that CreateDefaultBuilder only have the info from appsettings after
    IWebHostBuilder is Build()?

B) add UseConfiguration with the code above in the initial question.
files are with:

- launchSettings.json:
      "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development",
    "ASPNETCORE_SHUTDOWNTIMEOUTSECONDS" : "50"
  }
- appsettings.json:
"SHUTDOWNTIMEOUTSECONDS": 30

I was expecting to get 50 because in LoadConfiguration we do AddEnvironmentVariables() after AddJsonFile("appsettings.json"...)

Thanks in advance.

from hosting.

Tratcher avatar Tratcher commented on August 22, 2024

AddEnvironmentVariables isn't working because you need to specify the prefix in order for the matching to work correctly: AddEnvironmentVariables("ASPNETCORE_").

hostBuilder.GetSettings reads only from the host config, where appsettings isn't loaded later until the app's config is build. That's why UseConfiguration works, it loads the config immediately into the host config.

from hosting.

imxavi avatar imxavi commented on August 22, 2024

Hi, understood.
Thank You.

from hosting.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.