Question

When I run workerRole on Azure, throw me the following exception:

An unhandled exception of type 'System.TypeInitializationException' occurred in Google.Apis.Auth.dll

Additional information: Se produjo una excepción en el inicializador de tipo de 'Google.Apis.Json.NewtonsoftJsonSerializer'.

This is the code that break execution:

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;
}

I know that the "GoogleClientSecrets.Load(stream).Secrets" throws the exception because method Load() returns null value, but stream is full. Anybody have a idea?

Thanks, Roger

EDIT:

{System.TypeInitializationException: Se produjo una excepción en el inicializador de tipo de '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. La definición del manifiesto del ensamblado no coincide con la referencia al ensamblado. (Excepción de HRESULT: 0x80131040) en Google.Apis.Json.NewtonsoftJsonSerializer..cctor() --- Fin del seguimiento de la pila de la excepción interna --- 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ínea 55 en AzureConnection.BigQueryCon.getAuth() en c:\Users\user\Documents\AzureConnection\AzureConnection\BigQueryCon.cs:línea 34}

Was it helpful?

Solution

I have solved it. The problem was in app.config of WorkerRole project. My solution has 2 projects: ApplicationProject and WorkerRoleProject

I solve the problem copying the missing dependentAssembly in app.config in ApplicationProject to app.config in WorkerRoleProject

ApplicationProject - 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 project need the same dependentAssembly that ApplicationProject

That's All, Roger

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top