【问题标题】:RestSharp not working on WP7 TestsRestSharp 不适用于 WP7 测试
【发布时间】:2012-11-19 16:17:09
【问题描述】:

我正在尝试使用此类代码启动 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));

【问题讨论】:

    标签: silverlight windows-phone-7 nunit restsharp


    【解决方案1】:

    我知道 nunit 可以在 windows phone 7 上抛出奇怪的异常,确保你有 silverlight 版本,这可能会解决你的问题。 更多详情请点击此处 => NUnit with Windows Phone 7

    【讨论】:

    • 我还尝试了 MS 单元测试,并从 ReSharper(AgUnit 和不带)、Statlight、NCrunch 开始,使用不同的库,但仍然出现此错误。其他测试没有问题,只有RestSharp。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 2020-09-20
    相关资源
    最近更新 更多