• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2426
  • Last Modified:

string reference not set to an instance of a string


CultureInfo DefaultCulture = new CultureInfo("en-gb");
DefaultCulture = new CultureInfo(System.Configuration.ConfigurationManager.AppSettings["en-gb"]);

String reference not set to an instance of a string
Parameter name :name
0
PradeepYadhav
Asked:
PradeepYadhav
  • 2
  • 2
2 Solutions
 
AGBrownCommented:
What is the content of your .config file? In particular what is the full contents of the line
<add key ="en-gb" .....>
0
 
PradeepYadhavAuthor Commented:
<add key="TestCulture" value="en-gb"/>
0
 
PradeepYadhavAuthor Commented:
It is

<add key="DefaultCulture" value="en-gb"/>
0
 
AGBrownCommented:
Ah, in which case try:
DefaultCulture = new CultureInfo(System.Configuration.ConfigurationManager.AppSettings["TestCulture"]);
0
 
vo1dCommented:
i agree to agbrown.
but you should not make this call:
DefaultCulture = new CultureInfo(System.Configuration.ConfigurationManager.AppSettings["TestCulture"]);

you should evaluate your constructor arguments before using them:

CultureInfo DefaultCulture = null;
string testValue = System.Configuration.ConfigurationManager.AppSettings["TestCulture"];
if(testValue != null)
{
  DefaultCulture = new CultureInfo(testValue);
}
else
{
 //handle the uninitialized cultureinfo
}

regards, vo1d
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now