0

У меня проблема с API Google Analytics .NET. При подключении к GA через API на линииИсключение Google.Apis.Http.ConfigurableMessageHandler во время выполнения

 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 === 

Тип проекта: Console приложение
.NET Framework 4.0
MS Visual Studio 2010 Express
Windows Server 2003

Я пробовал тот же код в Windows 7, и он работает.
Я понятия не имею, что происходит не так.
Любая идея?

+0

проверить, что в GAC нет дополнительных DLL-плагинов или установите ссылочные dll для копирования локально. – DaImTo

+0

все внешние DLL-копии локальные: true, я думаю, что проблема может быть в том, что в C: \ Program Files \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.0 у меня не было файла System.Net.Http.dll, поэтому я добавил он использует команду gacuitl/i System.Net.Http.dll. Эта dll используется HttpClientFactory.cs. – PawelD

+0

@DalmTo Я проверил на второй машине Windows Server 2003 R2 и на этот раз во время выполнения VS попросил меня: c: \ code \ google.com \ google-api-dotnet-client \ default \ Tools \ Google.Apis.Release \ bin \ Debug \ test \ default \ Src \ GoogleApis.Core \ Apis \ Http \ HttpClientFactory.cs – PawelD

ответ

1

Похоже, ваш основной проблемой является внутреннее исключение вы получили:

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, как предложено здесь: Could not load file or assembly System, Version=2.0.5.0 in .NET 4 MVC 4 application

+0

Спасибо, этот патч решил мою проблему. – PawelD

Смежные вопросы