0
我试图创建WebRequest
的实例,但它引发异常。WebRequest.Create抛出System.NullReferenceException
代码:
WebRequest request = WebRequest.Create("somURL");
错误:
System.NullReferenceException: Object reference not set to an instance of an object.
此代码工作对当地的环境,但没有客户生产服务器上。
注意:客户端最近更改了托管。 .Net Framework是3.5。
全部例外:
System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() 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(String requestUriString) at
是。在这条线上。 –
请发布完整的例外,包括其调用堆栈,而不仅仅是消息。你可以用'Exception.ToString'获得完整的例外 –
@PanagiotisKanavos,你给出了很好的提示 –