{"id":2513,"date":"2022-08-30T15:25:29","date_gmt":"2022-08-30T15:25:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/27\/when-working-with-web-config-configuration-class-is-not-available-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:25:29","modified_gmt":"2022-08-30T15:25:29","slug":"when-working-with-web-config-configuration-class-is-not-available-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/when-working-with-web-config-configuration-class-is-not-available-collection-of-common-programming-errors\/","title":{"rendered":"When working with web.config, Configuration class is not available-Collection of common programming errors"},"content":{"rendered":"<p>I want to access the &#8220;appSettings&#8221; section of a web.config file. According to MSDN and multiple other sources, the following should work:<\/p>\n<pre><code>System.Configuration.Configuration config = \n    WebConfigurationManager.OpenWebConfiguration(\"\/rootPath\");\n<\/code><\/pre>\n<p>I received this error on the second configuration (System.Configuration.<b>Configuration<\/b>):<\/p>\n<blockquote>\n<p>The type or namespace name &#8216;Configuration&#8217; does not exist in the namespace &#8216;System.Configuration'(are you missing an assembly reference?)<\/p>\n<\/blockquote>\n<p>I received an additional error on system (<b>System<\/b>.Configuration.Configuration):<\/p>\n<blockquote>\n<p>The type &#8216;System.Configuration.Configuration&#8217; is defined in an assembly that is not referenced. You must add a reference to assembly &#8216;System.Configuration, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a&#8217;.<\/p>\n<\/blockquote>\n<p>Addressing the first error, I have a reference to System.Configuration. When I look in Object Browser, it contains a class definition for Configuration.<\/p>\n<p>Addressing the second error, the reference is for version 2.0.50727. Is there a version 2.0.0.0?<\/p>\n<p>The second error popped up after I deleted, and re-added the reference to System.Configuration. Also, after re-adding the reference it now displays as &#8220;System.<b>c<\/b>onfiguration&#8221; in my references. Note the lowercase c.<\/p>\n<p><b>Additional Notes<\/b><br \/>\nThings I&#8217;ve tried and failed:<\/p>\n<ul>\n<li>Deleted and added the reference to System.Configuration<\/li>\n<li>Deleted all references for the project and added them back<\/li>\n<li>Checked out a clean solution from SVN<\/li>\n<\/ul>\n<p>I created a test solution and had no problems accessing the class in the System.Configuration namespace.<\/p>\n<p>Any ideas on what is going on (how did I eff this up)? What avenues can I try to fix it?<\/p>\n<ol>\n<li>\n<p>This is so stupid, I want to delete this question and quietly back away. Perhaps it&#8217;ll be useful to some other fool. Eilon was on the right track, I was adding the reference to the <b>wrong project<\/b>.<\/p>\n<p>I was in a time crunch trying to get a project production ready and was not very focused (trying to do several things at once). Ah well, I&#8217;m still new to this and hopefully next time I will take a deep breath and not stress out&#8230;and start the project out with connection strings stored in the web config.<\/p>\n<\/li>\n<li>\n<p>Try to remove that references to <code>System.Configuration<\/code> and do it from scratch: you should to add <code>version=2.0.0.0<\/code> (for <strong>runtime<\/strong> version v2.0.50727). Then, to read your <code>appSetting<\/code>, you could just write this:<\/p>\n<pre><code>string value = System.Configuration.ConfigurationManager.AppSettings[\"yourKey\"];\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-27 08:43:03. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I want to access the &#8220;appSettings&#8221; section of a web.config file. According to MSDN and multiple other sources, the following should work: System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(&#8220;\/rootPath&#8221;); I received this error on the second configuration (System.Configuration.Configuration): The type or namespace name &#8216;Configuration&#8217; does not exist in the namespace &#8216;System.Configuration'(are you missing an assembly reference?) I received [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2513","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2513"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2513\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}