Will ConfigurationManager.AppSettings["blah"] throw an exception if "blah" doesn't exist in the web/app.config?
Sincere apologies for the super lazy question.
Will ConfigurationManager.AppSettings["blah"] throw an exception if "blah" doesn't exist in the web/app.config?
Sincere apologies for the super lazy question.
Yes http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx
Edit: this is clearly wrong. Left for the helpful comments below.
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 is found and its associated value is null. This property does not distinguish between the two cases.
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 key is not found and null which is returned because the value associated with the key is null.
(my emphasis)
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 cases: 1) if the specified key is not found; and 2) if the specified key is found and its associated value is a null reference (Nothing in Visual Basic). This method does not distinguish between the two cases.