string reference not set to an instance of a string

Posted on 2006-04-13
Last Modified: 2007-12-19

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
Question by:PradeepYadhav
    LVL 12

    Expert Comment

    What is the content of your .config file? In particular what is the full contents of the line
    <add key ="en-gb" .....>

    Author Comment

    <add key="TestCulture" value="en-gb"/>

    Author Comment

    It is

    <add key="DefaultCulture" value="en-gb"/>
    LVL 12

    Accepted Solution

    Ah, in which case try:
    DefaultCulture = new CultureInfo(System.Configuration.ConfigurationManager.AppSettings["TestCulture"]);
    LVL 11

    Assisted Solution

    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);
     //handle the uninitialized cultureinfo

    regards, vo1d

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now