I have a problem: app throws InvalidCastException when I creating HttpWebRequest in BackgroundAgent. This code works in App foreground tasks, but doesn't works in BackgroundAgent:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(//InvalidCastException
new Uri(url));
request.BeginGetResponse(r => {
HttpWebRequest httprequest = (HttpWebRequest)r.AsyncState;
try {
Full code: http://pastebin.com/zyCHBQuP