Configuration Class Denied Permission

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
In my development environment Ive the following three sections of code.  Item #1 and #3 work but #2 poops out on me.  Im going this just to study up on configuration stuff.  Anways, I get an error when #2 tries to run:
  <font size=2></font><font color="#2b91af" size=2><font size=2>
</font><font color="#008000" size=2>//#1 obselete way to retrieve configuration values </font><font size=2>
</font><font color="#2b91af" size=2>Console</font><font size=2>.WriteLine(</font><font color="#a31515" size=2>"Obselete: "</font><font size=2> + </font><font color="#2b91af" size=2>ConfigurationSettings</font><font size=2>.AppSettings[</font><font color="#a31515" size=2>"CompanyName"</font><font size=2>]);
</font><font color="#008000" size=2>  </font><font size=2>
</font><font color="#008000" size=2>//#2 this first example uses the file based approach - any file can be indicated. </font><font size=2>
</font><font color="#2b91af" size=2>Configuration</font><font size=2> cs = </font><font color="#2b91af" size=2>ConfigurationManager</font><font size=2>.OpenExeConfiguration(</font><font color="#2b91af" size=2>ConfigurationUserLevel</font><font size=2>.PerUserRoamingAndLocal);
</font><font color="#2b91af" size=2>Console</font><font size=2>.WriteLine(</font><font color="#a31515" size=2>"File Based Approach: "</font><font size=2> + cs.AppSettings[</font><font color="#a31515" size=2>"CompanyName"</font><font size=2>]);
</font><font color="#008000" size=2></font> 
<font color="#008000" size=2>//#3 this second example uses the configuration manager outright </font><font size=2>
</font><font color="#2b91af" size=2>Console</font><font size=2>.WriteLine(</font><font color="#a31515" size=2>"Direct Approach: "</font><font size=2> + </font><font color="#2b91af" size=2>ConfigurationManager</font><font size=2>.AppSettings[</font><font color="#a31515" size=2>"CompanyName"</font><font size=2>]); </font></font>
<font size=2></font> 
 I get the following error when #2 tries to run:
System.Configuration.ConfigurationElement.this [System.Configuration.ConfigurationProperty] is inaccessible due to its protection level.
 
 

View the full article
 
Back
Top