nuget包Google.Apis.Auth
在我的项目中将引用添加到Google.Apis.Auth.PlatformServices
,但nuget的dll版本为1.9.1.12399
,似乎Google.Apis.Auth
需要版本{{1而你可以在下面抛出的异常中看到。
我尝试将1.9.1.12397
添加到app.config和machine.config,但它无效。
这是一个例外:
<bindingRedirect oldVersion="1.9.1.12397" newVersion="1.9.1.12399" />
这是我的代码:
System.IO.FileNotFoundException: Could not load file or assembly 'Google.Apis.PlatformServices, Version=1.9.1.12397, Culture=neutral, PublicKeyToken=null' or on
e of its dependencies. The system cannot find the file specified.
File name: 'Google.Apis.PlatformServices, Version=1.9.1.12397, Culture=neutral, PublicKeyToken=null'
at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsyncCore>d__e.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsyncCore(Initializer initializer, IEnumerable`1 scopes, String user, CancellationToken task
CancellationToken, IDataStore dataStore)
at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__1.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 59
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at GoogleTasker.Program.<>c__DisplayClass4.<<Main>b__0>d__6.MoveNext() in c:\Users\User\Documents\Visual Studio 2013\Projects\GoogleTasker\GoogleTasker\Progr
am.cs:line 29
=== Pre-bind state information ===
LOG: DisplayName = Google.Apis.PlatformServices, Version=1.9.1.12397, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///c:/users/user/documents/visual studio 2013/Projects/GoogleTasker/GoogleTasker/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Google.Apis.Auth.PlatformServices, Version=1.9.1.12399, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\users\user\documents\visual studio 2013\Projects\GoogleTasker\GoogleTasker\bin\Debug\GoogleTasker.vshost.exe.Confi
g
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/GoogleTasker/GoogleTasker/bin/Debug/Google.Apis.PlatformServices
.DLL.
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/GoogleTasker/GoogleTasker/bin/Debug/Google.Apis.PlatformServices
/Google.Apis.PlatformServices.DLL.
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/GoogleTasker/GoogleTasker/bin/Debug/Google.Apis.PlatformServices
.EXE.
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/GoogleTasker/GoogleTasker/bin/Debug/Google.Apis.PlatformServices
/Google.Apis.PlatformServices.EXE.
App.config中:
static void Main(string[] args)
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
Task.Run(async () =>
{
try
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { "https://www.googleapis.com/auth/tasks" },
"user",
CancellationToken.None,
new FileDataStore("Store")
);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
throw;
}
}
);
}
}