0

The nuget package Google.Apis.Auth adds a reference in my project to Google.Apis.Auth.PlatformServices, but the dll version from nuget is 1.9.1.12399 and it seems that Google.Apis.Auth needs version 1.9.1.12397 instead as you can see in the exception thrown below.

I tried to add <bindingRedirect oldVersion="1.9.1.12397" newVersion="1.9.1.12399" /> to app.config and machine.config but it won't work.

This is the exception:

    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.

And this is my code:

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;
                    }

                }
            );
        }
    }

App.config:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Google.Apis.Auth.PlatformServices" publicKeyToken="null" culture="neutral" />
        <bindingRedirect oldVersion="1.9.1.12397" newVersion="1.9.1.12399" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
Andrei Dvoynos
  • 1,126
  • 1
  • 10
  • 32
  • This is weird, in our samples repository there are different versions of those dlls - https://github.com/google/google-api-dotnet-client-samples/blob/master/Drive.Sample/Drive.Sample.csproj. Can you please verify that you are using the latest version of NuGet and try to create a new project from the beginning? – peleyal Apr 16 '15 at 14:17
  • It helps to look at your code one week later :) The error is actually a missing reference to "Google.Apis.PlatformServices". The reference being added is to "Google.Apis.**Auth**.PlatformServices". No idea there were several PlatformServices dll, that's why I was confused. Either way, shouldn't the install-package cmd pull that reference as well? – Andrei Dvoynos Apr 20 '15 at 07:04
  • Google.Apis.PlatformServices is a different dll for each platforms (full dotnet profile, windows phone, windows store, etc.). When installing the Google.Apis and Google.Apis.Auth package, NuGet install the right dlls for you, take a look in this file - https://github.com/google/google-api-dotnet-client/blob/master/Tools/Google.Apis.Release/Resources/Google.Apis.VERSION.nuspec#L40 it might help you understand the different. – peleyal Apr 20 '15 at 13:31
  • @peleyal Ok, I think that my problem came from installing only Google.Apis.Auth. I thought that Google.Apis was a dependency and it would have been installed automatically by nuget, but it didn't, at least not correctly. After installing both one after the other, it worked correctly! – Andrei Dvoynos Apr 20 '15 at 15:50
  • Great! Why did you want to install only Google.Apis.Auth? Are you working with a specific API? If so, the API should have a dependency in Google.Apis.Auth and Google.Apis. – peleyal Apr 20 '15 at 18:47
  • I just wanted to reuse the authentication part. I'm using Tasks and Calendar API, but I have a custom library for the REST calls. That's why I just added Google.Apis.Auth. – Andrei Dvoynos Apr 21 '15 at 16:28
  • Don't you want to use the Google.Apis.Calendar and Google.Apis.Task NuGet packages? – peleyal Apr 22 '15 at 17:05

0 Answers0