Could not load type 'Google.Apis.Requests.IErrorResponseHandler' from assembly 'Google.Apis'

白昼怎懂夜的黑 提交于 2020-01-15 15:30:37

问题


I am Google Auth api Calendar in .net. I have copied the code from this link:Refresh Token Expiration time Google calendar Could not load type 'Google.Apis.Requests.IErrorResponseHandler' from assembly 'Google.Apis, Version=1.6.0.16897, Culture=neutral, PublicKeyToken=null'

Here is my code:

private CalendarService CreateService(string token)
    {
        //KeyValuePair<string, string> credentials = Ninject.Web.Common.Get3LOCredentials();
        var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, this.clientID, this.ClientSecret);
        //provider.ClientIdentifier = clientID;
        //provider.ClientSecret = clientSecret;
        var auth = new Google.Apis.Authentication.OAuth2.OAuth2Authenticator<NativeApplicationClient>(provider, (p) => GetAuthorization(provider, token));
        CalendarService service = new CalendarService(new BaseClientService.Initializer()
        {
            Authenticator = auth,
            ApiKey = ConfigurationManager.AppSettings[this.APIkey].ToString(),
            GZipEnabled = false
        });
        return service;
    }

    private static IAuthorizationState GetAuthorization(NativeApplicationClient arg, String Refreshtoken)
    {
        IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
        state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
        state.RefreshToken = Refreshtoken;
        return state;
    }

回答1:


Did you use package manager to install the API?

Further onwards, Are you going to request access everytime or do you want to save the refreshtoken so that you can get a non-expired access token when you make following calls?




回答2:


I solved this problem by uninstalling and re-installing the NuGet package "google.apis.auth". This was because multiple versions are installed.

  1. Right click on the "References" menu of the project. Manually remove all package references related to google.apis.auth.

  2. Then, select "Manage NuGet Package", search for "google.apis.auth", and uninstall "google.apis.auth".

  3. Reinstall the same package.

  4. Clean and rebuild

If it doesn't work, you might try reinstall "google.apis" as well.



来源:https://stackoverflow.com/questions/20541298/could-not-load-type-google-apis-requests-ierrorresponsehandler-from-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!