blfuentes
blfuentes

Reputation: 2827

GetAppSetting from Azure returning null

I am developing a chatbot azure-service. It actually works, but I am having problems while trying to debug it.

I configured the bot framework emulator following the steps from https://learn.microsoft.com/en-us/bot-framework/bot-service-debug-emulator

Again, it seems to work. Connection is established.

Only problem is regarding the way I have to get the appsettings to read the different API keys.

In the base code I downloaded from azure settings are read like this:

var qnaSubscriptionKey = Utils.GetAppSetting("QnASubscriptionKey");
var qnaKBId = Utils.GetAppSetting("QnAKnowledgebaseId");

But it always returns null .I changed to

var qnaSubscriptionKey = ConfigurationManager.AppSettings["QnASubscriptionKey"];
var qnaKBId = ConfigurationManager.AppSettings["QnAKnowledgebaseId"];

so I read the settings from the Web.config file.

Checking this link: http://www.c-sharpcorner.com/article/setting-and-reading-values-from-app-settings-json-in-net-core/ If I understood it correctly, appsettings is for .NET core applications.

My chatbot dll is using .NET 4.7.1.

Is there a way I can read the appsettings.json or should I just use the ConfigurationManager approach?

Upvotes: 0

Views: 598

Answers (1)

Älskar
Älskar

Reputation: 2577

.NET 4.x projects use XML .config files to express application settings. And the way to access these is either to use ConfigurationManager or CloudConfigurationManager.

.NETCore makes use of json files to express application settings. Here are fundamentals for reading config values in .NetCore.

Upvotes: 1

Related Questions