Share via

How do add and read appsettings in Visual Code?

Chaumette Garcia 0 Reputation points
Mar 6, 2024, 6:40 PM

I'm using Visual Code and I want set values in the appsettings file. Then retrieve them using Configuration Manager - see below - I'm getting following error:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at Program.Main() in C:\Chaumette\Development\IntuneTokenApp\Program.cs:line 11

Visual Code is new to me- I'm not sure why it's not finding the value. I manually added appSettings.config - Is there any special configuration needed?

User's image



var applicationId = ConfigurationManager.AppSettings["appId"].ToString();
.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,103 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,342 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.