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.
Google Drive SDK fetch causes unhandled exception
-
29-03-2022 - |
문제
I'm trying to handle network failure exceptions when using Google Drive SDK and I have the following problem. I'm disconnecting my network and running this code
try
{
FilesResource.InsertRequest r = service_.Files.Insert(body);
r.Fetch();
} catch
{
Console.WriteLine("Error");
}
but instead of printing "Error" the application is terminated due to unhandled exception. Debugger shows the following stack trace
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)
Looks like Fetch()
does some asynchronous operations inside and the exception is not handled. So I can't find a way handling this exception. It always terminates my application. How can I fix that?
update
I found this line of code
Stream bodyStream = request.EndGetRequestStream(asyncResult);
in Src\GoogleApis.Tests\Apis\Requests\RequestTest.cs:731
EndGetRequestStream throws an exception which is unhandled by the thread, so it looks like this is a bug in Client API. Am I right? Any workarounds?
update
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?
해결책
다른 팁
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.