Printscreen of my code with the error and my references. There is an error with the 'ApplicationException', and I just don't know how to resolve it.
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 notification:
Error CS0246 The type or namespace name 'ApplicationException' could not be found (are you missing a using directive or an assembly reference?) 25
The ApplicationException class isn't available in Portable Class Libraries and ASP.NET vNext projects, which I think your project is.
More importantly:
You should derive custom exceptions from the
Exceptionclass rather than theApplicationExceptionclass. You should not throw anApplicationExceptionexception in your code, and you should not catch anApplicationExceptionexception unless you intend to re-throw the original exception.
So use Exception when you throw an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With