How do add and read appsettings in Visual Code?

Chaumette Garcia 0 Reputation points
2024-03-06T18:40:38.41+00:00

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();
Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | 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.
{count} votes

Your answer

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