创建UserCredential时抛出错误;

时间:2014-12-24 09:40:24

标签: c# asp.net .net google-api

我收到的错误是:

  

无法加载文件或程序集'System.Core,Version = 2.0.5.0,   Culture = neutral,PublicKeyToken = 7cec85d7bea7798e,Retargetable = Yes'或   其中一个依赖项。给定的程序集名称或代码库是   无效。 (来自HRESULT的异常:0x80131047)

执行使用google API v3在我的网站上集成Google日历的代码:

代码是:

     public bool connectCalendar()
        {
            ClientSecrets secrets = new ClientSecrets
            {
                ClientId = "10xxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxx82.apps.googleusercontent.com",
                ClientSecret = "LxxxxxxxxxxxXYEb3Iaxo3C"
            };
            CalendarService calendarConnection;                try
            {
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, new string[]{
                    CalendarService.Scope.Calendar}, "user",
                    CancellationToken.None, new FileDataStore("Books.ListMyLibrary")).Result;
//exception is thrown in this line
                var initializer = new BaseClientService.Initializer();
                initializer.HttpClientInitializer = credential;
                initializer.ApplicationName = "secret-heaven-798";
                calendarConnection = new CalendarService(initializer);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
            return true;
        } 

我引用此link,为什么会出现此错误?我做错了什么?

我已将这些行添加到Web配置文件中:

  <dependentAssembly>
    <assemblyIdentity name="System.Core" PublicKeyToken="7cec85d7bea7798e" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>

1 个答案:

答案 0 :(得分:1)

您的解决方案的一个组件依赖于System.Core,Version = 2.0.5.0。这个程序集应该在你的解决方案的bin目录中(我不知道是web,还是win等)或GAC。很可能你不会在你的环境中安装这个程序集。