[英]"Error Deserializing JSON Credential Data" gcp auth file c#
繼this question之后,我想打開一個相關的來驗證答案。 最初我的代碼看起來像
string path2key = "C:/Users/me/Downloads/project-id-1-letters.json";
string jsonString = File.ReadAllText(path2key);
Console.WriteLine(jsonString); // this works and prints correctly
// I presume I'm passing json as a string???
var credential = GoogleCredential.FromJson(jsonString);
但我收到以下錯誤
System.InvalidOperationException: 'Error deserializing JSON credential data.'
FileNotFoundException: Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
我正在使用 .netframework 4.5,這意味着我在將軟件包更新到最新和最好方面有些受限。
另一個答案是正確的。 我正要發布相同的答案,但@serge 搶先一步。
class GoogleCredentials有一個成員FromJson 。 該成員采用字符串參數。 在您的代碼中,您試圖傳遞 object。
對於您對答案的評論中的錯誤:
FileNotFoundException: Could not load file or assembly 'System.Security.Permissions
可以通過使用 nuget package 管理器並添加System.Security.Permissions或通過 CLI 來更正該錯誤:
dotnet add package System.Security.Permissions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.