10

We're seeing a very strange issue when running the following application from a network share under NET4.0. When specifying a defaultProxy section in app.config a System.Net.WebException is thrown. There is no problem when running from a local drive.

According to documentation applications will run as full-trust assemblies from a network share so we're assuming this should work just fine.

Any ideas how we can work around this problem?

Has anyone else experienced this issue or does anyone know why this might be happening?

Sample program

using System;
using System.Net;

namespace ProxyTest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                String s = new WebClient().DownloadString("http://www.google.com");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}

app.config

  <?xml version="1.0"?>
  <configuration>
    <system.net>
      <defaultProxy useDefaultCredentials="true"/>
    </system.net>
    <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
    </startup>
  </configuration>

Exception details

System.Net.WebException: An exception occurred during a WebClient request. ---> System.Configuration.ConfigurationErrorsException: Insufficient permissions for setting the configuration section 'defaultProxy'. ---> System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
   at System.Security.CodeAccessPermission.Demand()
   at System.Net.Configuration.DefaultProxySection.PostDeserialize()
   --- End of inner exception stack trace ---
   at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
   at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
   at System.Net.Configuration.DefaultProxySectionInternal.GetSection()
   at System.Net.WebRequest.get_InternalDefaultWebProxy()
   at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint)
   at System.Net.HttpRequestCreator.Create(Uri Uri)
   at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
   at System.Net.WebRequest.Create(Uri requestUri)
   at System.Net.WebClient.GetWebRequest(Uri address)
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   --- End of inner exception stack trace ---
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadString(Uri address)
   at System.Net.WebClient.DownloadString(String address)
   at ProxyTest.Program.Main(String[] args) in Y:\Program.cs:line 12
Karl Andersson
  • 103
  • 1
  • 1
  • 4

2 Answers2

13

See this Microsoft Knowledge Base article:

Symptoms:

  • You run a Microsoft .NET Framework 4-based application that is stored on a network share.
  • The application calls a static method in the System.Configuration.ConfigurationManager class. For example, the application calls the ConfigurationManager.GetSection method.

In this scenario, a System.Security.SecurityException exception is thrown and then the application crashes.

Cause:

The issue occurs because the method fails to access configuration section from the application on network share.

You can request the hotfix from that site.

adrianbanks
  • 81,306
  • 22
  • 176
  • 206
Joe
  • 146
  • 1
  • 2
  • Annoyingly it would seem this hotfix is no longer available, but the problem still certainly exists... – Stafford Williams May 23 '12 at 05:09
  • I believe that the hotfix is still available. The download link in the email sent by MS for the hotfix incorrectly contains a trailling closing bracket. Remove that and the download works OK. – daveywc Jul 26 '12 at 02:46
  • The download is available when removing the closing parenthesis, however it does not unzip. It keeps asking for the second disk. – Paul Nov 15 '12 at 16:13
  • 2
    Does anyone know if Microsoft have patched this or do we have to ask our customers to install a hotfix from Microsoft? – Marcus Feb 14 '13 at 11:15
  • Just for Google references: The French error message reads similar to `Autorisations insuffisantes pour la définition de la section de configuration 'defaultProxy'.` – Sébastien Nussbaumer Feb 27 '15 at 09:17
5

We've seen similar symptoms - same error message

Insufficient permissions for setting the configuration section 'defaultProxy'

when running a Console application where the files were 'blocked'.

The files had been installed by downloading a zip file from a hyperlink and the zip file wasn't 'unblocked' before unzipping.

Unblocking all the files (you have to do them individually in Windows) from Explorer > right-click > Properties > Unblock resolved the problem.

Rory
  • 40,559
  • 52
  • 175
  • 261
  • Worked for me. Thanks Rory. I don't know whether the two issues are related. – mcNux Jun 12 '13 at 10:28
  • Just for Google references: The German error message reads similar to `"Ungenügende Berechtigungen zum Festlegen des Konfigurationsabschnitts "defaultProxy"`. – Uwe Keim Mar 28 '14 at 16:22
  • Worked for me but I could do the "unblock" from the properties of the config file only, and my problem was that I transferred the config file from somewhere else than the application code. My solution was, Config-file-> right-click->properties->unblock – Zafer Sernikli Aug 11 '14 at 08:15