Google.Apis.Json.NewtonsoftJsonSerializer抛出异常

时间:2014-02-05 15:44:19

标签: c# json.net google-oauth azure-worker-roles google-api-dotnet-client

当我在Azure上运行workerRole时,抛出以下异常:

  

Google.Apis.Auth.dll中出现未处理的“System.TypeInitializationException”类型异常

其他信息:Se produjounaexpepciónenel inicializador de tipo de'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(stream).Secrets”会抛出异常,因为方法Load()返回null值,但是stream已满。有人有想法吗?

谢谢, 罗杰

编辑:

  

{System.TypeInitializationException:Se produjounaexpepciónenel 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 depedencias。 Ladefinicióndelmanifiesto del ensamblado没有重合con la referencia al ensamblado。 (ExcepcióndeHRESULT:0x80131040)      en Google.Apis.Json.NewtonsoftJsonSerializer..cctor()      --- Fin del seguimiento de la pila delaexcepcióninterna---      zh.Google.Apis.Json.NewtonsoftJsonSerializer.get_Instance()      zh.Google.Apis.Auth.OAuth2.GoogleClientSecrets.Load(Stream stream)zh 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()c:\ Users \ user \ Documents \ AzureConnection \ AzureConnection \ BigQueryCon.cs:línea34}

1 个答案:

答案 0 :(得分:3)

我已经解决了。问题出在WorkerRole项目的app.config中。我的解决方案有2个项目:ApplicationProject和WorkerRoleProject

我解决了将ApplicationProject中app.config中缺少的dependentAssembly复制到WorkerRoleProject中的app.config的问题

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项目需要与ApplicationProject相同的dependentAssembly

这就是全部, 罗杰