i want create simple section without writing class myself, have read other posts , tried building own section throws exception of system.invalidcastexception when try section. tell me how can solve it? thanks!
exception message:
an unhandled exception of type 'system.invalidcastexception' occurred in httpserver.exe
additional information: unable cast object of type 'system.configuration.keyvalueinternalcollection' type 'system.configuration.appsettingssection'.
app.config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configsections> <section name="extensions" type="system.configuration.appsettingssection" /> </configsections> <extensions> <add key=".gif" value="image/gif"/> <add key=".png" value="image/png"/> <add key=".jpg" value="image/jpeg"/> </extensions> <startup> <supportedruntime version="v4.0" sku=".netframework,version=v4.5" /> </startup> </configuration>
c# code:
appsettingssection section = (appsettingssection)configurationmanager.getsection("extensions"); console.writeline(section.settings[".gif"].value.tostring());
change system.configuration.appsettingssection system.configuration.namevaluesectionhandler , value system.collections.specialized.namevaluecollection
Comments
Post a Comment