Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Google.api.Json.NewtonsoftJsonSerializer引发异常_C#_Json.net_Google Oauth_Azure Worker Roles_Google Api Dotnet Client - Fatal编程技术网

C# Google.api.Json.NewtonsoftJsonSerializer引发异常

C# Google.api.Json.NewtonsoftJsonSerializer引发异常,c#,json.net,google-oauth,azure-worker-roles,google-api-dotnet-client,C#,Json.net,Google Oauth,Azure Worker Roles,Google Api Dotnet Client,在Azure上运行workerRole时,抛出以下异常: Google.api.Auth.dll中发生类型为“System.TypeInitializationException”的未处理异常 其他信息:Se produjo una excepción en el-inicializador de tipo de‘Google.api.Json.newtonsoftjsonalizer’ 这是中断执行的代码: private static byte[] jsonSecrets = Propert

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

Google.api.Auth.dll中发生类型为“System.TypeInitializationException”的未处理异常

其他信息:Se produjo una excepción en el-inicializador de tipo de‘Google.api.Json.newtonsoftjsonalizer’

这是中断执行的代码:

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()返回空值,但流已满。有人有主意吗

谢谢, 罗杰

编辑:

{System.TypeInitializationException:Se produjo una excepción en el-inicializador de tipo de'Google.api.Json.NewtonsoftJsonSerializer'。-->System.IO.FileLoadException:No Se puede cargar el archivo o ensamblado'Newtonsoft.Json,Version=4.5.0.0,Culture=中立,publicyToken=30ad4fe6b2a6需要'ni una de sus dependenicias.La definicicódel m恩萨姆布拉多参考文献不一致。(人权结果除外:0x8013100) en Google.api.Json.NewtonsoftJsonSerializer..cctor() ---国际社会的例外情况--- en Google.api.Json.NewtonsoftJsonSerializer.get_Instance() en Google.api.Auth.OAuth2.GoogleClientSecrets.Load(Stream Stream)en c:\code\Google.com\Google api dotnet client\default\Tools\Google.api.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}


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

我解决了将ApplicationProject中app.config中缺少的dependentAssembly复制到WorkErrorProject中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

仅此而已,
罗杰

阅读InnerException。我用InnerException编辑原始帖子你可以尝试创建一个新的ClientSecrets{ClientID=“…”,ClientSecret=“…”}而不是使用“GoogleClientSecrets.Load(stream).Secrets”?你会得到同样的错误吗?如果我这样做,会引发其他异常:{System.IO.FileLoadException:No se puede cargar el archivo o ensamblado'System.Net.Http.Primitives,Version=1.5.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'ni una de sus dependencias.La definiticón del manifiesto del ensamblado No con La referencea al-ensambladoNombre de archivo:'System.Net.Http.Primitives,Version=1.5.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'我已经解决了它。稍后我将解释解决方案。问题与NuGet库版本有关