Ich entwickle gerade eine C# -App, die auf Linux-Instanzen über Mono läuft. Sie müssen Bilder in Google Cloud Storage speichern, wenn sie verarbeitet wurden.In C#/Mono, nicht in der Lage, mit Google Cloud-Speicher zu kommunizieren
Ich habe die Authentifizierung Credentials-Setup und die .NET-Client-Bibliothek kann das StorageService
-Objekt einrichten (d. H. Die JSON-Datei finden und alles validieren). Als ich versuchte hochzuladen, passierte nichts. In meiner SetupConnection()
Funktion habe ich versucht, den einzelnen Bucket, den ich in meinem Projekt habe, abzufragen. Ich habe diesen Fehler:
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
Hier ist mein Setup-Code:
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());
}
}
Ich habe in der Lage gewesen, bevor C# sprechen GCS, aber das war, als ich in einer Windows-Umgebung arbeitete, mit Microsoft .NET vm. Ich habe vorher ein wenig recherchiert und es könnte einige Probleme damit geben, wie Mono mit CAs im Gegensatz zu Microsofts VM zurechtkommt.
Welche Version von Mono? Führen Sie 'mono --version' am Terminal aus. –
Es ist 'Mono JIT Compiler Version 3.2.8' – Benjamin
das ist zu alt. Upgrade zuerst durch das Studium seiner Website, http://www.mono-project.com/ –