2016-04-04 60 views
0

我正在開發一個C#應用程序,現在通過Mono在Linux實例上運行。它需要將圖像存儲在Google雲端存儲中。在C#/單聲道,無法與谷歌雲存儲

我有auth憑據設置,.NET客戶端庫能夠設置StorageService對象(即查找JSON文件並驗證所有內容)。當我嘗試上傳時,什麼都沒有發生。所以在我的SetupConnection()函數中,我試圖查詢我的項目中的單個存儲桶。我得到這個錯誤:

Unhandled Exception: 
System.Net.WebException: Error writing request: The authentication or decryption has failed. 
    at System.Net.WebConnectionStream.WriteHeaders() [0x00000] in <filename unknown>:0 
    at System.Net.WebConnectionStream.SetHeaders (System.Byte[] buffer) [0x00000] in <filename unknown>:0 
    at (wrapper remoting-invoke-with-check) System.Net.WebConnectionStream:SetHeaders (byte[]) 
    at System.Net.HttpWebRequest.SendRequestHeaders (Boolean propagate_error) [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Http.ConfigurableMessageHandler+<SendAsync>d__43.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions+<ExecuteAsync>d__0.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[Google.Apis.Auth.OAuth2.Responses.TokenResponse].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.ServiceAccountCredential+<RequestAccessTokenAsync>d__19.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Boolean].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.ServiceCredential+<GetAccessTokenForRequestAsync>d__23.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.String].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.ServiceAccountCredential+<GetAccessTokenForRequestAsync>d__20.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.String].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.ServiceCredential+<InterceptAsync>d__21.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Http.ConfigurableMessageHandler+<SendAsync>d__43.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Requests.ClientServiceRequest`1+<ExecuteUnparsedAsync>d__26[Google.Apis.Storage.v1.Data.Buckets].MoveNext() [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.WebException: Error writing request: The authentication or decryption has failed. 
    at System.Net.WebConnectionStream.WriteHeaders() [0x00000] in <filename unknown>:0 
    at System.Net.WebConnectionStream.SetHeaders (System.Byte[] buffer) [0x00000] in <filename unknown>:0 
    at (wrapper remoting-invoke-with-check) System.Net.WebConnectionStream:SetHeaders (byte[]) 
    at System.Net.HttpWebRequest.SendRequestHeaders (Boolean propagate_error) [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Http.ConfigurableMessageHandler+<SendAsync>d__43.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions+<ExecuteAsync>d__0.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[Google.Apis.Auth.OAuth2.Responses.TokenResponse].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.ServiceAccountCredential+<RequestAccessTokenAsync>d__19.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Boolean].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.ServiceCredential+<GetAccessTokenForRequestAsync>d__23.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.String].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.ServiceAccountCredential+<GetAccessTokenForRequestAsync>d__20.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.String].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Auth.OAuth2.ServiceCredential+<InterceptAsync>d__21.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Http.ConfigurableMessageHandler+<SendAsync>d__43.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext() [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x00000] in <filename unknown>:0 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult() [0x00000] in <filename unknown>:0 
    at Google.Apis.Requests.ClientServiceRequest`1+<ExecuteUnparsedAsync>d__26[Google.Apis.Storage.v1.Data.Buckets].MoveNext() [0x00000] in <filename unknown>:0 

這是我的設置代碼:

public static void SetupGCSConnection() 
{ 
    var credentials = Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync().Result; 

    if (credentials.IsCreateScopedRequired) 
     credentials = credentials.CreateScoped(new[] { StorageService.Scope.DevstorageFullControl }); 

    var serviceInitializer = new BaseClientService.Initializer() 
    { 
     ApplicationName = "MyApp", 
     HttpClientInitializer = credentials 
    }; 

    storage = new StorageService(serviceInitializer); 

    // Error is thrown here 
    var buckets = storage.Buckets.List(Config.GoogleProjectID).Execute(); 
    foreach (var b in buckets.Items) { 
     Console.WriteLine(b.ToString()); 
    } 
} 

我已經能夠得到C#交談GCS之前,但當時我在Windows環境下工作,與微軟的.NET虛擬機。我之前做了一些研究,Mono處理CA與微軟VM相比,可能存在一些問題。

+0

哪個版本的Mono?在終端運行'mono --version'。 –

+0

這是'單聲道JIT編譯器版本3.2.8' – Benjamin

+0

太舊了。首先通過研究他的網站升級,http://www.mono-project.com/ –

回答

0

您的問題通常來自根證書未被更新。

按照說明here更新您的根證書。

如果沒有幫助,那麼你可以委託設置爲

ServicePointManager.ServerCertificateValidationCallback 

並接受所有證書。如果有效,那麼您知道問題出在證書驗證上,您可以嘗試其他解決方案。 (我永遠不會建議使用回調來接受生產中的所有證書,只是用它來調試你的問題)。