【问题标题】:Google Drive SDK fetch causes unhandled exceptionGoogle Drive SDK 提取导致未处理的异常
【发布时间】:2013-03-21 11:31:30
【问题描述】:

我在使用 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 中的错误。我对吗?有什么解决方法吗?

更新

有答案吗?这是非常重要的。每次断开网络连接时,我的应用程序都会崩溃,如果不接触 Google API 源代码,就无法解决这个问题。我将BeginGetResponse() 更改为GetResponse() 并重新编译了代码,所以目前它适用于我并且Fetch() 按预期抛出异常,但是同步和异步操作共享一个公共代码(同步操作执行异步并等待)所以目前我无法进行异步获取。你们会解决这个问题吗?

更新

谷歌说We support the Google Drive SDK on Stack Overflow。 伙计们,你们真的为你们的 SDK 提供某种支持吗?我正在等待将近 5 天的任何答案。有人吗?

【问题讨论】:

    标签: google-drive-api unhandled-exception google-api-dotnet-client


    【解决方案1】:

    抱歉耽搁了。 它看起来像一个错误,我刚刚在我们的问题跟踪器中打开了一个新问题 - 您可以向它添加更多详细信息 here。 我们将尝试在下一个版本中修复它。

    【讨论】:

      【解决方案2】:

      在接下来的几周内,我们将发布 1.4.0-beta 版本,该版本修复了这个问题。只是让您知道,新版本的 Google.Apis 核心库将是PCL。需要将.NET框架升级到4.0,TPL的用处很大。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多