我有带有代码的便携式类库(net40+sl4+win8+wp71):
public static async Task<Dictionary<string, FeedItem>> GetFeeds()
{
try
{
string data;
using (HttpMessageHandler handler = new HttpClientHandler())
{
using (HttpClient httpClient = new HttpClient(handler))
{
data = await httpClient.GetStringAsync(FeedsUrl + Guid.NewGuid()).ConfigureAwait(false);
}
}
if (data != null)
{
//...
}
return null;
}
catch
{
return null;
}
}
引用了 Microsoft.Bcl、Microsoft.Bcl.Async 和 Microsoft.Net.Http。
我在 Windows 8 Metro 应用程序中使用这个库。然后我通过VS2012调试应用程序,就可以了。但是当我创建应用程序包并安装它时,应用程序在每次启动时都会崩溃并出现错误:
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException
Stack:
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(System.Object)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
编辑:如果我注释行“data = await httpClient.GetStringAsync”,它将毫无例外地工作。
在第二次启动时,它始终有效。
有什么建议吗?