Answer by Kasper for Will ConfigurationManager.AppSettings["blah"] throw an...
As Tim said, it will just return null.However, if you want it to throw an exception when not found one could do this:var myImportantSetting= ConfigurationManager.AppSettings["important_setting"] ??...
View ArticleWill ConfigurationManager.AppSettings["blah"] throw an exception if "blah"...
Will ConfigurationManager.AppSettings["blah"] throw an exception if "blah" doesn't exist in the web/app.config? Sincere apologies for the super lazy question.
View ArticleAnswer by Ben for Will ConfigurationManager.AppSettings["blah"] throw an...
Yes http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx Edit: this is clearly wrong. Left for the helpful comments below.
View ArticleAnswer by Tim Robinson for Will ConfigurationManager.AppSettings["blah"]...
No, it returns null.
View ArticleAnswer by Martin Liversage for Will ConfigurationManager.AppSettings["blah"]...
From the MSDN documentation for NameValueCollection.Item Property (String): Caution This property returns null in the following cases: 1) if the specified key is not found; and 2) if the specified key...
View ArticleAnswer by Andrew for Will ConfigurationManager.AppSettings["blah"] throw an...
No, it returns null. ConfigurationManager.AppSettings is a NameValueCollection - from the MSDN documentation: The Get method does not distinguish between null which is returned because the specified...
View ArticleAnswer by Dexter for Will ConfigurationManager.AppSettings["blah"] throw an...
No, it returns null. AppSettings is a NameValueCollection - as per the caution on the NameValueCollection.Get page: This method returns a null reference (Nothing in Visual Basic) in the following...
View ArticleAnswer by Scott Munro for Will ConfigurationManager.AppSettings["blah"] throw...
Other answers reference the documentation for the Item property. It might not be immediately obvious why they are relevant looking at the following code snippet....
View Article