'ApplicationException' 找不到
'ApplicationException' could not be found
Printscreen 我的代码错误和我的参考资料。
'ApplicationException' 有错误,我只是不知道如何解决它。
using System;
using System.Net;
using System.Net.Http;
namespace Sharepoint_2013_REST_API
{
public class Program
{
public void Main(string[] args)
{
//Init
string baseURL = "hello";
string uriString = "world";
System.Net.Http.HttpClient _Client = new System.Net.Http.HttpClient();
_Client.BaseAddress = new Uri(baseURL);
HttpResponseMessage resp = _Client.GetAsync(uriString).Result;
string respString = resp.Content.ReadAsStringAsync().Result;
if (resp.StatusCode != HttpStatusCode.OK)
{
throw new ApplicationException("BAD");
}
}
}
}
错误通知:
Error CS0246 The type or namespace name 'ApplicationException' could not be found (are you missing a using directive or an assembly reference?) 25
ApplicationException
class 在便携式 Class 库和 ASP.NET vNext 项目中不可用,我认为你的项目是。
更重要的是:
You should derive custom exceptions from the Exception
class rather than the ApplicationException
class. You should not throw an ApplicationException
exception in your code, and you should not catch an ApplicationException
exception unless you intend to re-throw the original exception.
所以当你抛出异常时使用Exception
。
Printscreen 我的代码错误和我的参考资料。 'ApplicationException' 有错误,我只是不知道如何解决它。
using System;
using System.Net;
using System.Net.Http;
namespace Sharepoint_2013_REST_API
{
public class Program
{
public void Main(string[] args)
{
//Init
string baseURL = "hello";
string uriString = "world";
System.Net.Http.HttpClient _Client = new System.Net.Http.HttpClient();
_Client.BaseAddress = new Uri(baseURL);
HttpResponseMessage resp = _Client.GetAsync(uriString).Result;
string respString = resp.Content.ReadAsStringAsync().Result;
if (resp.StatusCode != HttpStatusCode.OK)
{
throw new ApplicationException("BAD");
}
}
}
}
错误通知:
Error CS0246 The type or namespace name 'ApplicationException' could not be found (are you missing a using directive or an assembly reference?) 25
ApplicationException
class 在便携式 Class 库和 ASP.NET vNext 项目中不可用,我认为你的项目是。
更重要的是:
You should derive custom exceptions from the
Exception
class rather than theApplicationException
class. You should not throw anApplicationException
exception in your code, and you should not catch anApplicationException
exception unless you intend to re-throw the original exception.
所以当你抛出异常时使用Exception
。