0

I started using Visual Code instead of VS- Unfortunately, I can't figure out how to setup appSettings.config and reference the key values using Configuration Manager.

This line throws a Nullreference exception:

var applicationId = ConfigurationManager.AppSettings["appId"].ToString();

I manually added the file appSettings.config when I created the console application. Here's the Folder structure:

enter image description here

Is there additional configuration needed?

4
  • 1
    There's no appsettings.config in .NET. In .NET Framework settings are stored in app.config and accessed through ConfigurationManager or Properties.Settings. The weekly typed AppSetting is a remnant of .NET Framework 1, way back in 2002. Newer versions use strongly typed ApplicationSettings that can be edited using a VS GUI designer, accessible through Properties.Settings. Commented Mar 7, 2024 at 10:53
  • 2
    .NET Core (which includes .NET 5 and later) doesn't use any of this. There isn't even a ConfigurationManager any more. They use a far more powerful and easier Configuration Middleware, with appsettings.json just one of the sources. Commented Mar 7, 2024 at 10:54
  • 2
    If you use Visual Studio Code you're probably using .NET Core, in which case you shouldn't use ConfigurationManager at all. Libraries and NuGet packages work expect settings through the Configuration middleware. Commented Mar 7, 2024 at 10:56
  • Thank you all - renaming it app.config worked. Commented Mar 7, 2024 at 14:10

1 Answer 1

0

I needed to rename appsettings.config to app.config.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.