fix null reference error when configuration setting specified by "keyName" parameter doesnt exist.

#79
This commit is contained in:
chris.watts90@outlook.com 2017-04-21 08:03:32 +01:00
parent 23ade491e6
commit 20f0ccb211

View File

@ -1,4 +1,5 @@
using System.Configuration; using System.Configuration;
using System.Linq;
namespace ConfigurationHandler namespace ConfigurationHandler
{ {
@ -7,7 +8,9 @@ namespace ConfigurationHandler
public static string GetConfiguration(string keyName) public static string GetConfiguration(string keyName)
{ {
var appSettings = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetEntryAssembly().Location).AppSettings; var appSettings = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetEntryAssembly().Location).AppSettings;
return appSettings.Settings[keyName].Value; if(appSettings.Settings.AllKeys.Contains(keyName))
return appSettings.Settings[keyName].Value;
return string.Empty;
} }
} }
} }