RestSharp不能用于WP7测试

时间:2012-11-19 16:17:09

标签: silverlight windows-phone-7 nunit restsharp

我正在尝试使用以下代码启动WP7测试:

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

此代码写入HttpStatusCode = 0并引发错误:

  

'System.Net.WebRequest'的类型初始化程序引发了异常。   System.TypeInitializationException

如何解决?

更新#1

例如,此代码在Windows类库中可以正常工作,但在Silverlight和WP7项目中不起作用:

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));

1 个答案:

答案 0 :(得分:0)

我知道nunit可以在Windows Phone 7上抛出奇怪的异常,确保你有Silverlight版本,这可能会解决你的问题。 这里有更多细节=> NUnit with Windows Phone 7