0

I'm trying to launch test for WP7 with such code:

var client = new RestClient("http://google.com");
var request = new RestRequest(Method.GET);
client.ExecuteAsync(request, response => Debug.WriteLine(response.StatusCode);

This code write HttpStatusCode=0 and raise error:

The type initializer for 'System.Net.WebRequest' threw an exception. System.TypeInitializationException

How to fix it?

UPDATE #1

For example, this code works fine in Windows Class Library, but doesn't work in Silverlight and WP7 Projects:

var client = new RestClient("http://carma.org/api/1.1/searchPlants");
var request = new RestRequest();
request.AddParameter("location", 4338);
request.AddParameter("limit", 10);
request.AddParameter("color", "red");
request.AddParameter("format", "xml");
var plants = client.ExecuteAsync(
request, response => Assert.AreEqual(HttpStatusCode.OK, response.StatusCode));
Anton Kandybo
  • 3,678
  • 4
  • 23
  • 31

1 Answers1

0

I know that nunit can throw strange exception on windows phone 7, make sure you got the silverlight version, that may fix your problem. More details are availables here => NUnit with Windows Phone 7

Community
  • 1
  • 1
MarcD
  • 314
  • 1
  • 8
  • I also tried MS Unit Tests and started with ReSharper (AgUnit and without), Statlight, NCrunch, with different libraries, but this error still occurs. There are no problems in other tests, only with RestSharp. – Anton Kandybo Nov 19 '12 at 23:31