0

我在使用 Google Drive SDK 时尝试处理网络故障异常,但遇到以下问题。我正在断开网络并运行此代码

try
{
    FilesResource.InsertRequest r = service_.Files.Insert(body);
    r.Fetch();
} catch
{
    Console.WriteLine("Error");
}

但是由于未处理的异常而终止了应用程序,而不是打印“错误”。调试器显示以下堆栈跟踪

Unable to connect to the remote server
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
   at Google.Apis.Requests.Request.EndAttachBody(IAsyncResult asyncResult) in c:\code.google.com\google-api-dotnet-client\default_release\Tools\BuildRelease\bin\Debug\output\default\Src\GoogleApis\Apis\Requests\Request.cs:line 714
   at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at System.Net.ContextAwareResult.CompleteCallback(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   at System.Net.HttpWebRequest.SetResponse(Exception E)
   at System.Net.HttpWebRequest.SetAndOrProcessResponse(Object responseOrException)
   at System.Net.ConnectionReturnResult.SetResponses(ConnectionReturnResult returnResult)

看起来Fetch()里面做了一些异步操作并且没有处理异常。所以我找不到处理这个异常的方法。它总是终止我的应用程序。我该如何解决?

更新

我找到了这行代码

Stream bodyStream = request.EndGetRequestStream(asyncResult);

Src\GoogleApis.Tests\Apis\Requests\RequestTest.cs:731

EndGetRequestStream引发了一个线程未处理的异常,因此看起来这是客户端 API 中的一个错误。我对吗?任何解决方法?

更新

Any answers? That's very important. My application crashes every time I disconnect the network and this cannot be solved without touching Google API source codes. I changed BeginGetResponse() to GetResponse() and recompiled the code, so currently it works for me and Fetch() throws an exception as expected, but synchronous and asynchronous operations are sharing a common code (synchronous operation executes asynchronous and waits) so currently I can't do async fetch. Will you guys fix this?

update

Google says We support the Google Drive SDK on Stack Overflow. Guys, do you really provide kind of support for your SDK? I'm waiting for ANY answer almost 5 days. Is there anybody?

4

2 回答 2

2

Sorry for the delay. It looks like a bug and I just opened a new issue in our issue tracker - you can add more details to it here. We will try to fix it in the next release.

于 2013-03-25T10:49:42.170 回答
0

In the next couple of weeks we are going to publish version 1.4.0-beta which has a fix for this problem. Just to let you know, the new version of Google.Apis core library will be PCL. It requires upgrading the .NET framework to 4.0, and there is a great usage of TPL.

于 2013-06-07T01:21:36.363 回答