If you’re still having trouble, feel free to reply and share the relevant parts of your code (including appsettings.json). Go take a look at the file and see if it’s what you expect. Please respond with the reference number you receive via email so I can escalate the issue for you. Please mention that it's ' u/Mental-Kitty from Reddit' along with a description of your issue. Var filePath = Path.Combine(, "appsettings.json") Console.WriteLine("File is here: " + filePath) You can do so by clicking on the question mark at the top of the screen then clicking Report a Problem. You can print out the file path for troubleshooting: If it exists and the name is right, then you’re probably loading the wrong appsettings.json accidently (or it isn’t being copied to the build output folder, so doesn’t have your class in it). If you’re using the right name with config.GetSection(), then verify that the section exists in appsettings.json.ģ. Verify you are using the right name with config.GetSection(): var section = config.GetSection("ThisIsTheWrongName") //This would return an empty IConfigurationSection since it’s the wrong name var weatherClientConfig = section.Get() Ģ. When you use config.GetSection(), it returns an empty IConfigurationSection if the section doesn’t exist in the appsettings.json.Ĭheck three things: 1. ![]() Section.Get() returns null if it’s an empty IConfigurationSection. Here’s an example of displaying a property from the config on the IndexModel Now you can use this in the Model or Page. Because you’re using the new project template (where everything is in Main()), read the config and register the custom config class in Main(): Follow the first two original steps since they’re the same (add a custom class + put settings in appsettings.json).Ģ.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
June 2023
Categories |