运行时出现Google.Apis.Http.ConfigurableMessageHandler异常

保罗

我对Google Analytics(分析)API .NET有问题。在通过api通过api连接到GA时

        var certificate = new X509Certificate2(pathToPrivateKey, passToPrivateKey, X509KeyStorageFlags.Exportable);
        ServiceAccountCredential credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmailAddress)
        {
            Scopes = scopes
        }.FromCertificate(certificate));

它给出以下错误

Message=The type initializer for 'Google.Apis.Http.ConfigurableMessageHandler' threw an exception.
  Source=Google.Apis.Core
  TypeName=Google.Apis.Http.ConfigurableMessageHandler
  StackTrace:
   at Google.Apis.Http.ConfigurableMessageHandler..ctor(HttpMessageHandler httpMessageHandler)
   at Google.Apis.Http.HttpClientFactory.CreateHttpClient(CreateHttpClientArgs args) in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis.Core\Apis\Http\HttpClientFactory.cs:line 37
   at Google.Apis.Auth.OAuth2.ServiceAccountCredential..ctor(Initializer initializer) in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis.Auth.DotNet4\OAuth2\ServiceAccountCredential.cs:line 217
   at ConsoleApplication3.Program.AuthenticationGA(String pathToPrivateKey, String serviceAccountEmailAddress, String passToPrivateKey) in C:\Documents and Settings\pivotaladmin.WA-PIV\my documents\visual studio 2010\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs:line 30
   at ConsoleApplication3.Program.Main(String[] args) in C:\Documents and Settings\pivotaladmin.WA-PIV\my documents\visual studio 2010\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs:line 69
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.IO.FileLoadException
   Message=Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
   Source=Google.Apis.Core
   FileName=System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes
   FusionLog==== Pre-bind state information ===

项目类型:控制台应用程序
.NET Framework 4.0
MS Visual Studio 2010 Express
Windows Server 2003

我在Windows 7上尝试了相同的代码,并且可以正常工作。
我不知道出了什么问题。
任何的想法?

Peleyal

看来您的主要问题是所获得的内部异常:

InnerException: System.IO.FileLoadException
 Message=Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral,
 PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. 

好消息是,您应该按照以下建议安装以下补丁:KB2468871无法在.NET 4 MVC 4应用程序中加载文件或程序集系统,版本= 2.0.5.0

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TOP 榜单

热门标签

归档