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

  • Home
  • SEARCH
  • 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 4091804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:24:46+00:00 2026-05-20T19:24:46+00:00

I have a custom profile defined in my webconfig. I have this property defined

  • 0

I have a custom profile defined in my webconfig. I have this property defined

<add name="sex" type="bool" serializeAs="String" defaultValue="[null]"/>

as there are null values in the database. I get a null reference exception in this code:

    ProfileCommon p = GetProfile();
            txtFirstName.Text = p.first_name;
            txtLastName.Text = p.last_name;
            txtInitial.Text = p.initial;
            txtEmail.Text = p.email;

//this causes an null reference exception
bool? blnTest = p.sex;

Is this the correct way to set a default null value in webconfig?

  • 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-20T19:24:46+00:00Added an answer on May 20, 2026 at 7:24 pm

    The problem here is that the default type of a profile property is bool which is not a nullable type. It will always default to false.

    You could always create a custom class to encapsulate Sex / Gender and use this instead of bool. That way when there is no value set the class will then attempt to instantiate and revert to null as required.

    Changes to web config:

     <profile defaultProvider="MyProfileProvider" inherits="FTS.Membership.Profile.MyProfileProvider,FTS.Membership">
          <providers>
            <clear/>
            <add name="MyProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="FTS.Membership.Profile.MyProfileProvider,FTS.Membership"/>
          </providers>
          <properties>
            <add name="first_name" type="string" serializeAs="String" defaultValue=""/>
            <add name="last_name" type="string" serializeAs="String" defaultValue=""/>
            <add name="initial" type="string" serializeAs="String" defaultValue=""/>
            <add name="email" type="string" serializeAs="String"/>
            <add name="active" type="bool" serializeAs="String" defaultValue="false"/>
            <add name="creation_date" type="datetime" serializeAs="String"/>
            <add name="update_date" type="datetime" serializeAs="String"/>
            <add name="last_activity_date" type="datetime" serializeAs="String"/>
            <!--<add name="sex" type="bool" serializeAs="String" defaultValue="false"/>-->
    
          </properties>
        </profile>
    

    and the class:

    using System;
    using System.Web.Profile;
    using System.Collections.Generic;
    
    namespace FTS.Membership.Profile
    {
        public class MyProfileProvider : ProfileBase
        {
            public bool? sex
            {
                get {
                    if (base["sex"] == null)
                    {
                        return null;
                    }
                    return (bool)base["sex"];
                }
                set { base["sex"] = value; }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom content type called 'business-profile' and I have the template files
I have a custom class named Profile and a NSMutableArray which I add the
Textmate does not source my .profile file. I don't have a custom bash_init.rb, nor
hi i would like to create a custom calendar, this calendar will have custom
I have extended Django's User Model using a custom user profile called UserExtension .
I have written a custom shell script function, and put in in my .profile
I have a phpBB installation. I've added custom profile field called 'insurance number'. Every
I have a custom event handler on a wiki page, which should add a
I have set up a custom firefox profile and load it when selenium RC
I am trying to create a custom profile to add additional fields to django-registration

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.