Search code examples
asp.netconfigurationsitemapweb-configwebconfigurationmanager

WebConfigurationManager error after adding siteMap


I'm getting this error:

Compiler Error Message: CS0118: 'Configuration' is a 'namespace' but is used like a 'type' Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");

This code has been in place for 5+ months without this issues, only today after adding this sitemap code do I have this issue.

<siteMap defaultProvider="ExtendedSiteMapProvider" enabled="true">
            <providers>
                <clear/>
                <add name="ExtendedSiteMapProvider" type="Configuration.ExtendedSiteMapProvider" siteMapFile="Web.sitemap" securityTrimmingEnabled="true"/>
            </providers>
        </siteMap>

I tried adding "System.Web." before the "Configuration ", but that did not work either:

System.Web.Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");

Error 1 'System.Web.Configuration' is a 'namespace' but is used like a 'type'


Solution

  • System.Configuration.Configuration instead of System.Web.Configuration

            // Get the configuration object for a Web application
            // running on the local server. 
            System.Configuration.Configuration config =
                WebConfigurationManager.OpenWebConfiguration("/~") 
                as System.Configuration.Configuration;