c# - Configuration Section Settings Not Initializing -


i've spent several hours trying determine what's causing custom configuration section fail, can't seem find root of issue.

i'm getting error:

an exception of type 'system.configuration.configurationerrorsexception' occurred in system.configuration.dll not handled in user code

additional information: value property 'afdatabase' not valid. error is: string must @ least 1 characters long.

looking @ configuration section, started off noticing have string validator set up:

configuration cs

public class tankconfigurationsection : configurationsection {     [configurationproperty("afserver", isrequired = true)]     [stringvalidator(invalidcharacters = "~!@#$%^&*()[]{}/;'\"|\\", minlength = 0, maxlength = 60)]     public string afserver     {                 {             return (string)this["afserver"];         }         set         {             this["afserver"] = value;         }     }      [configurationproperty("afdatabase",  isrequired = true)]     [stringvalidator(invalidcharacters = "~!@#$%^&*()[]{}/;'\"|\\", minlength = 1, maxlength = 60)]     public string afdatabase     {                 {             return (string)this["afdatabase"];         }         set         {             this["afdatabase"] = value;         }     }     [configurationproperty("tanktemplate", isrequired = true)]     [stringvalidator(invalidcharacters = "~!@#$%^&*()[]{}/;'\"|\\", minlength = 1, maxlength = 60)]     public string tanktemplate     {                 {             return (string)this["tanktemplate"];         }         set         {             this["tanktemplate"] = value;         }     }  } 

i removed string validator requirement 1 character length on afserver, , noticed error occurs on afdatabase. seems me values never being initialized, , that's why when afserver has minlength of 1, fails, removing it, error falls on afdatabase.

here web.config:

    <configuration>     <!-- configuration section-handler declaration area. -->   <configsections>     <sectiongroup name="tankconfigurationgroup">       <section          name="tankconfiguration"          type="tankinventory.configurations.tankconfigurationsection"         allowlocation="true"          allowdefinition="everywhere"       />     </sectiongroup>       <!-- other <section> , <sectiongroup> elements. -->   </configsections>    <!-- configuration section settings area. --> <tankconfigurationgroup>           <tankconfiguration afserver ="test123" afdatabase ="test123" tanktemplate ="test21345" >         </tankconfiguration>       </tankconfigurationgroup> </configuration> 

i've been using guide: https://msdn.microsoft.com/en-us/library/2tw134k3.aspx

try this

<configsections>       <section name="tankconfiguration" type="tankinventory.configurations.tankconfigurationsection"     allowlocation="true"      allowdefinition="everywhere"   /> 

      <tankconfiguration afserver ="test123" afdatabase ="test123" tanktemplate ="test21345"/>> 


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -