1

當我在Azure上運行workerRole,把我扔以下異常:Google.Apis.Json.NewtonsoftJsonSerializer拋出一個異常

型「System.TypeInitializationException」未處理的異常發生在Google.Apis.Auth。 dll的

其他信息:東南produjo UNAexcepción恩報德inicializador德TIPO 'Google.Apis.Json.NewtonsoftJsonSerializer'。

這是代碼中斷執行:

private static byte[] jsonSecrets = Properties.Resources.client_secrets; 

using (var stream = new MemoryStream(jsonSecrets, true)) 
{ 
    GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store"; 
    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets, 
      new[] { BigqueryService.Scope.Bigquery, BigqueryService.Scope.CloudPlatform }, 
      "user", 
      CancellationToken.None, 
      new FileDataStore("Bigquery.Auth.Store")).Result; 
} 

我知道「GoogleClientSecrets.Load(流).Secrets」拋出異常,因爲方法Load()返回空值,但流滿了。任何人有想法?

感謝, 羅傑

編輯:

{System.TypeInitializationException:硒produjo UNAexcepción恩報德inicializador德TIPO 'Google.Apis.Json.NewtonsoftJsonSerializer'。 ---> System.IO.FileLoadException:No se puede cargar el archivo o ensamblado'Newtonsoft.Json,Version = 4.5.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed'ni una de sus dependencias。 Ladefinicióndel manifiesto del ensamblado no coincide con la referencia al ensamblado。 (Excepciónde HRESULT:0x80131040) en Google.Apis.Json.NewtonsoftJsonSerializer..cctor() --- Fin del seguimiento de la pila de laexcepcióninterna --- en Google.Apis.Json.NewtonsoftJsonSerializer.get_Instance( ) en Google.Apis.Auth.OAuth2.GoogleClientSecrets.Load(Stream stream)en c:\ code \ google.com \ google-api-dotnet-client \ default \ Tools \ Google.Apis.Release \ bin \ Debug \ output \ default \ Src \ GoogleApis.Auth \ OAuth2 \ GoogleClientSecrets.cs:línea55 en AzureConnection.BigQueryCon.getAuth()en c:\ Users \ user \ Documents \ AzureConnection \ AzureConnection \ BigQueryCon.cs:línea34}

+0

閱讀InnerException。 – SLaks

+0

我使用innerException編輯原始文章 – RCalaf

+0

您可以嘗試創建新的ClientSecrets {ClientID =「...」,ClientSecret =「...」}而不是使用「GoogleClientSecrets.Load(stream).Secrets」?你有同樣的錯誤嗎? – peleyal

回答

2

我已經解決了。問題出在WorkerRole項目的app.config中。我的解決方案有2個項目:ApplicationProject和WorkerRoleProject

我解決問題複製在ApplicationProject的app.config dependentAssembly缺少WorkerRoleProject

ApplicationProject到的app.config - 的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.0.10.0" newVersion="4.0.10.0"/> 
    </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="1.2.13.0" /> 
    </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
    </dependentAssembly> 
</assemblyBinding> 

WorkerRoleProject項目需要相同的依賴程序集ApplicationProject

就是這樣, Roger