Zoinky
Zoinky

Reputation: 5019

ConfigurationProperty not returning DefaultValue incase it doesnt exist

[ConfigurationProperty("spatialSRID", DefaultValue = 4326)]
public int SpatialSRID
{
    get { return (int)this["SpatialSRID"]; }
    set { this["SpatialSRID"] = value; }
}

My understand of the above code is that if I do not define the section "SpatialSRID" in my web.config file it will resort to returning 4326 as it has been set as default. However it returns null hence my code blows up.

Now i know i can check for nulls, but I thought that was the purpose of DefaultValue.

Upvotes: 1

Views: 687

Answers (1)

Zoinky
Zoinky

Reputation: 5019

Issue: case sensitivity

[ConfigurationProperty("spatialSRID", DefaultValue = 4326)]
public int SpatialSRID
{
    get { return (int)this["spatialSRID"]; }
    set { this["spatialSRID"] = value; }
}

Upvotes: 1

Related Questions