Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cannot get value from configuration file
Message
De
04/03/2015 07:06:16
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 5.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01616171
Message ID:
01616192
Vues:
33
>I have a DLL library that uses a configuration file to get a value which can be set at the client.
>The configuration file contains:
>
> <appSettings>
>    <add key="CertificateSerialNumber" value="SerialNumber"/>
>  </appSettings>
>
>In the code of the library I try to get the serial number:
>
>SerialNumber = ConfigurationSettings.AppSettings["CertificateSerialNumber"];
>
>Which works fine in debug, but when executing the code at the client, the subsequent error occurs:
>
>Value cannot be Null
>
>So I assume it cannot find the parameter I am looking for. The config file is in the same folder as the dll, so what am I missing?

When I run into something such as that it ends up being a minor spelling issue that I don't notice by glancing at it. I would wrap that call anyway in your own code somewhere making a method such as GetConfigSetting(). Pass in the key and also a default value for those times it doesn't contain a value.
then you can return
GetConfigSetting(string config, string default)
{
     string result = null;
     result = ConfigurationManager.AppSettings[config];
     return result  != null ? result : default;
}
Timothy Bryan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform