Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3421992
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:09:51+00:00 2026-05-18T06:09:51+00:00

I have a property that I’d like to type as int? in my Settings.settings

  • 0

I have a property that I’d like to type as int? in my Settings.settings file. When I use int? I get a runtime failure:

System.NullReferenceException: Object reference not set to an instance of an object..

I can use a string type as a workaround where a check for null works, but I have to parse the string and handle errors when the parse doesn’t work.

Being able to set the value to null allows me to keep the property documented in the settings file while making it obvious that no value has been set. When not set I use a programmed default value:

int? configuredNumberOfLimits = Settings.Default.RequiredNumberOfLimits;
if ( configuredNumberOfLimits == null  )
{
    requiredNumberOfLimits = DEFAULT_REQUIRED_NUMBER_LIMITS;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:09:52+00:00Added an answer on May 18, 2026 at 6:09 am

    There is a way to use nullable type (i.e. int?) for a setting – it requires a bit of manual editing of the settings file, but afterwards works fine in VS environment and in the code. And requires no additional functions or wrappers.

    To do this, create a setting with desired name (e.g. RequiredNumberOfLimit) and make it of any type (e.g. standard int for convenience).
    Save the changes.

    Now go to your project folder and open the “Properties\Settings.settings” file with text editor (Notepad, for example) Or you can open it in VS by right-clicking in Solution Explorer on “<Your Project> -> Properties -> Settings.settings”, select “Open With…” and then choose either “XML Editor” or “Source Code (Text) Editor”.
    In the opened xml settings find your setting (it will look like this):

    <Setting Name="RequiredNumberOfLimit" Type="System.Int32" Scope="User">
      <Value Profile="(Default)">0</Value>
    </Setting>
    

    Change the “Type” param from System.Int32 to System.Nullable<System.Int32>. And also clear the default value (so null could be used there by default).
    Now this section should look like this (note that &lt; and &gt; are used to represent < and > symbols inside the type string – this is done for correct parsing of xml by VS):

    <Setting Name="RequiredNumberOfLimit" Type="System.Nullable&lt;System.Int32&gt;" Scope="User">
      <Value Profile="(Default)" />
    </Setting>
    

    Now save changes and re-open project settings – voilà! – we have the setting RequiredNumberOfLimit with type System.Nullable<System.Int32> which is parsed correctly by VS Settings Designer, as well as it could be used as a normal int? variable in the code.

    If you want this setting to be able to return null you should keep the default value field clear.
    Otherwise, the default value will be returned by this setting if it was assigned to null previously (but thats how the default values work, don’t they? :P).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When you have some property that's like: using Algebra; public Algebra.Vector3 Direction { get
I have a property which looks like this. public int NumberOfElephants { get; set;
I have a string property that I would like to be able to force
I'm using application blocks and i have a property that use a Not Null
I have a property that I use to define a set of fields that
I have a property that returns System.Numerics.BigInteger . When I casting the property to
I would like to have a property that is always bound to the currently
I have a property that is assigned as: public string propertyA{get;set;} I want to
I have a Property that is an IEnumerable public IEnumerable<string> ChangesOthersResult { get; set;
I have a property that is tied to an SObject like so: public Decimal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.