title: How can I use the system.net section of my app.config in a partial trust environment?
body: <p>I've a WCF application deployed using clickonce.
  It connects to my server using https, and everything works fine</p>
  
  <p>I use the default proxy when needed thanks to the following code: </p>
  
  <pre><code>  &lt;configSections&gt;
      &lt;sectionGroup name="system.net" type="System.Net.Configuration.NetSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
        &lt;section name="defaultProxy" type="System.Net.Configuration.DefaultProxySection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/&gt;
      &lt;/sectionGroup&gt;
    &lt;/configSections&gt;
    &lt;system.net&gt;
      &lt;defaultProxy useDefaultCredentials="true"/&gt;
    &lt;/system.net&gt;
  </code></pre>
  
  <p>In Full Trust mode, everything works fine</p>
  
  <p>Now, if I set my security settings to partial trust, it does work fine if there's no proxy involved, but if I try to launch my software in a corporate environment, the proxy 
  is not autodetected anymore.</p>
  
  <p>From my understanding :</p>
  
  <p>The configSections are not parsed anymore in partial trust environments, unless the requirePermission attribute is set, like this : </p>
  
  <pre><code>&lt;section requirePermission="false" name="defaultProxy"&gt;
  </code></pre>
  
  <hr>
  
  <p>Setting this attribute throw a System.Configuration.ConfigurationException with the following error message :</p>
  
  <blockquote>
    <p>Section or group name 'defaultProxy'
    is already defined. Updates to this
    may only occur at the configuration
    level where it is defined.</p>
  </blockquote>
  
  <p>The 'defaultproxy' section is indeed already defined in the machine.config file :</p>
  
  <pre><code>   &lt;section name="defaultProxy" type="System.Net.Configuration.DefaultProxySection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/&gt;
  </code></pre>
  
  <p>However, this doesn't seem to be a problem as long as the requirePermission is not set. In other words, it seems that the error message should rather read :</p>
  
  <blockquote>
    <p>Section or group name 'defaultProxy'
    <strong>is already defined with another requirePermission setting</strong>. Updates to this
    may only occur at the configuration
    level where it is defined.</p>
  </blockquote>
  
  <hr>
  
  <p>Has somebody run into the same problem? Is it possible to silently use the default proxy from a WCF application in partial trust mode?
  I've also tried to set the proxy programatically, without success</p>
  
  <pre><code>System.Net.WebProxy proxy = new WebProxy();
  proxy.UseDefaultCredentials = true;
  WebRequest.DefaultWebProxy = proxy;
  </code></pre>
  
  <p>The useDefaultWebProxy attribute of the wshttpbinding is set straight from the beginning, but doesn't seem to work, either in a partial or full trust environment, without the 'system.net.defaultProxy' section correctly defined :</p>
  
  <pre><code>   &lt;binding name="WebBinding" useDefaultWebProxy="true"&gt;
  </code></pre>
  
  <p>I guess I could ask my clients to update their local machine.config files to add the needed defaultProxy useDefaultCredentials="true", but it's definitely not gonna ease deployment.</p>