1
我想用MonoDroid使用RestSharp,我遇到了一些問題。 MethodMissingException引發消息「找不到類型爲EmPubLite.Android.Tweet []的默認構造函數」。當我檢查VS調試器中的任務時,我只能看到異常,它不會顯示在LogCat中。我知道這個異常與RestSharp中的JSON反序列化有關。MonoDroid&RestSharp,MethodMissingException
在MonoDroid選項中鏈接器被設置爲'None',並且我也嘗試將[Preserve]屬性添加到我的DTO中。
除了讓這個工作,爲什麼不崩潰並顯示在LogCat?我希望任何失敗的異常任務在我訪問結果時重新拋出異常。
[Activity(Label = "EmPubLite", MainLauncher = true, Icon = "@drawable/icon")]
public class EmPubLiteActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.EmPubLight);
var client = new TwitterClient();
client.Search("bielema").ContinueWith(tweets =>
{
Debug.WriteLine("back");
Debug.WriteLine(tweets.Result[0].Text); // Exception not showing up in LogCat
});
}
}
public class TwitterClient
{
private RestClient client = new RestClient();
public Task<Tweet[]> Search(string query)
{
var request = new RestRequest("http://search.twitter.com/search.json?rpp=5&include_entities=true&result_type=mixed&q={q}", Method.GET);
request.AddUrlSegment("q", query);
var taskCompletionSource = new TaskCompletionSource<Tweet[]>();
client.ExecuteAsync<SearchResult>(request, response =>
{
if (response.ErrorException != null) taskCompletionSource.TrySetException(response.ErrorException);
else taskCompletionSource.TrySetResult(response.Data.Results);
// taskCompletionSource.TrySetResult(response.Data.Results);
});
return taskCompletionSource.Task;
}
}
public class SearchResult
{
public Tweet[] Results { get; set; }
}
public class Tweet
{
public string Text { get; set; }
}