我在使用 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?