configuration - custom section in app.config throws error in c# -


// winconfiguration.cs

using system; using system.configuration;  namespace banana.common {     public class winconfiguration : configurationsection     {         public readonly static banana.common.winconfiguration settings             = (banana.common.winconfiguration)system.configuration.configurationmanager.getsection("banana");          [configurationproperty("connections")]         public connectionscollection connections         {             { return (connectionscollection)this["connections"]; }         }          [configurationproperty("cryptography")]         public cryptographycollection cryptography         {             { return (cryptographycollection)this["cryptography"]; }         }     } } 

// app.config

<?xml version="1.0"?> <configuration>     <configsections>         <section name="banana" type="banana.common.winconfiguration"/>     </configsections>     <banana>         <connections>             <add name="sqlserver2008" connectionstring="" providername="system.data.sqlclient" priority="100" />         </connections>         <cryptography>             <add type="des" value="12345" />             <add type="tripledes" value="12345" />         </cryptography>     </banana>     <startup>         <supportedruntime version="v4.0" sku=".netframework,version=v4.0"/>     </startup> </configuration> 

it used work in web.config perfectly. changed class name. here web.config , custom configuration class.

// webconfiguration.cs

using system; using system.configuration;  namespace banana.common {     public class webconfiguration : configurationsection     {         public readonly static banana.common.webconfiguration settings = (banana.common.webconfiguration)system.web.configuration.webconfigurationmanager.getsection("banana");          [configurationproperty("connections")]         public connectionscollection connections         {             { return (connectionscollection)this["connections"]; }         }          [configurationproperty("cryptography")]         public cryptographycollection cryptography         {             { return (cryptographycollection)this["cryptography"]; }         }     } } 

// web.config

<?xml version="1.0" encoding="utf-8"?> <configuration>     <configsections>         <section name="banana" type="banana.common.webconfiguration"/>     </configsections>     <banana>         <connections>             <add name="sqlserver2008" connectionstring="" providername="system.data.sqlclient" priority="100" />         </connections>         <cryptography>             <add type="des" value="12345" />             <add type="tripledes" value="12345" />         </cryptography>     </banana> </configuration> 

it works fine webconfiguration.cs , web.config. winconfiguration.cs , app.config, gives me error "the type initializer 'banana.common.winconfiguration' threw exception.". can fix error me?

i think have specify assembly name (the name of exe or dll) configuration class resides:

<section name="banana" type="banana.common.winconfiguration, your_assembly_name"/> 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -