在Mono中配置System.Net的问题

时间:2013-09-06 10:06:06

标签: asp.net .net mono web-config

我尝试在Mono项目的Web.config中配置System.net节点。

我一直得到这个例外:

System.Configuration.ConfigurationErrorsException
Error deserializing configuration section defaultProxy: Unrecognized attribute 'enabled'. (/usr/share/nginx/aspnet/Web.config line 1)

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): System.Configuration.
Exception stack trace:
  at System.Configuration.ConfigurationSection.DeserializeSection (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSectionInstance (System.Configuration.SectionInfo config, Boolean createDefaultInstance) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationSectionCollection.get_Item (System.String name) [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSection (System.String path) [0x00000] in <filename unknown>:0 
  at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String path, System.Web.HttpContext context) [0x00000] in <filename unknown>:0 
  at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName) [0x00000] in <filename unknown>:0 
  at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in <filename unknown>:0 
  at System.Net.WebRequest.GetDefaultWebProxy () [0x00000] in <filename unknown>:0 
  at System.Net.WebRequest.get_DefaultWebProxy () [0x00000] in <filename unknown>:0 
  at System.Net.GlobalProxySelection.get_Select () [0x00000] in <filename unknown>:0 
  at System.Net.HttpWebRequest..ctor (System.Uri uri) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Net.HttpWebRequest:.ctor (System.Uri)
  at System.Net.HttpRequestCreator.Create (System.Uri uri) [0x00000] in <filename unknown>:0 
  at System.Net.WebRequest.Create (System.Uri requestUri) [0x00000] in <filename unknown>:0 
  at System.Net.WebClient.GetWebRequest (System.Uri address) [0x00000] in <filename unknown>:0 
  at System.Net.WebClient.SetupRequest (System.Uri uri) [0x00000] in <filename unknown>:0 
  at System.Net.WebClient.OpenRead (System.Uri address) [0x00000] in <filename unknown>:0 

我无法弄清楚如何让我的应用程序接受defaultProxy节点,并将enabled属性设置为true或使用其他一些设置。

如果从Web.config中删除System.net节点,则使用WebClient的应用程序部分会超时。

2 个答案:

答案 0 :(得分:2)

我相信你发现了单声道的错误。 DefaultProxySection constructor seems to forget to add the attribute properties to the collection,因此配置阅读器不了解它们。

请注意,enabled属性的默认值为true,因此您可以将该设置省略为解决问题的方法。

尽管如此,请在bugzilla.xamarin.com

中报告错误

答案 1 :(得分:1)

Necromancing。
要解决此错误,您可以设置

System.Net.WebRequest.DefaultWebProxy 

为NULL或

new System.Net.WebProxy();

在执行WebRequest之前。

示例:

System.Net.WebRequest.DefaultWebProxy = null;
System.Net.WebRequest.DefaultWebProxy = new System.Net.WebProxy();


System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)
System.Net.WebRequest.Create(URL);