【问题标题】:ASP.net app crashes - Could not load file or assembly 'Microsoft.Threading.Tasks.Extensions.Desktop'ASP.net 应用程序崩溃 - 无法加载文件或程序集“Microsoft.Threading.Tasks.Extensions.Desktop”
【发布时间】:2014-01-30 04:16:13
【问题描述】:

我想使用 OAuth2 和 .Net 4.5 框架构建一个 Google BigQuery C# ASP.net 应用程序。我运行了这些 NuGet 安装

Install-Package Google.Apis.Bigquery.v2 -Pre
Install-Package Google.Apis.Authentication.OAuth2 -Version 1.2.4696.27634

Install-Package Google.Apis -Pre
Install-Package Google.Apis.Auth -Pre

我将相关的“使用”放在代码隐藏文件“default.aspx.cs”中:

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Bigquery.v2;
using Google.Apis.Bigquery.v2.Data;

namespace BigQueryDemoApp
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UserCredential credential;
            FileStream stream;

            using (stream = new FileStream(
                    Server.MapPath("~/client_secrets.json"),
                    FileMode.Open, FileAccess.Read)
                )
            {
                GoogleWebAuthorizationBroker.Folder =
                    "Tasks.Auth.Store";
                credential = GoogleWebAuthorizationBroker.
                    AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { BigqueryService.Scope.Bigquery },
                    "user", CancellationToken.None).Result;
            }

            // Initialize the service.
            var Service = new BigqueryService(
                new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "BigQueryDemo"
                }
            );
        }
    }
}

我将此特定页面设置为项目开始页面。我在 Google 控制台上构建客户端 ID 文件时选择了“已安装的应用程序”

APIS & auth -> Credentials -> CREATE NEW CLIENT ID

我确保我在 VS2013 中使用解决方案资源管理器添加了这个文件 (client_secrets.json)。在代码隐藏中,我确保使用 Server.MapPath 正确映射到 client_secrets 文件。对于凭证机制,我使用了这段代码

<https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2>

作为起点。当我运行该应用程序时,它会返回一个以

开头的浏览器错误页面

无法加载文件或程序集“Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.16.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。系统找不到指定的文件。

并在“credential =”行崩溃。我试图添加一些实际 ASP.net 崩溃浏览器页面的图像,显​​示程序集负载跟踪/堆栈跟踪等,但看起来我没有此帐户权限。当我在“credential =”行设置断点然后运行应用程序时

DEBUG -> Start Debugging

在 VS2013 中,页面停在 "credential=" 行并打开文件选择器,查找文件

"GoogleClientSecrets.cs"

从目录

"c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis.Auth\OAuth2\GoogleClientSecrets.cs "

它不在驱动器上。在生成的 ASP.net 错误页面中使用程序集加载跟踪,我尝试通过建议的配置文件进行挖掘,但没有任何效果。更一般地说,我尝试在 StackOverflow 中寻找这个问题,虽然我确实找到了一些提及,但这些材料都没有帮助。

【问题讨论】:

    标签: asp.net .net google-api-dotnet-client


    【解决方案1】:

    由于该错误是基于最新版本的 Microsoft.Bcl.Async 无法在 .NET 4.5 中运行,您可以尝试执行以下操作:

    打开您的包管理器控制台,然后运行以下命令:
    1) 卸载包 Microsoft.Bcl.Async -Force
    2)安装包Microsoft.Bcl.Async -Version 1.0.16

    它适用于我目前正在编写的示例。请让我知道它是否适合您。

    更新(3 月 21 日): 您可以更新软件包(新版本 1.0.166-beta 可用 - https://www.nuget.org/packages/Microsoft.Bcl.Async/1.0.166-beta)。
    我在 VS2013 上使用 .NET 4.5 框架对其进行了测试,它可以工作。

    【讨论】:

    • 你好。抱歉耽搁了。我试过你的建议,它有效。谢谢你的帮助! - 弗兰克
    【解决方案2】:

    他们发布了新版本的-Package Microsoft.Bcl.Async。

    如果有人遇到此问题,请安装 "latest" 版本而不是 1.0.16。

    我希望它对你有用。

    【讨论】:

    • 非常明确:安装google API nuget包,然后添加当前的Microsoft.Bcl.Async,它将替换Google包引用的
    【解决方案3】:

    我之前已经遇到过这个错误。当您运行 .NET 4.0 应用程序时,Bcl.Async 包似乎包含对 Microsoft.Threading.Tasks.Extensions.Desktop 的引用,但不知何故,它在 .NET 4.5 应用程序中丢失了。

    我对您的建议(直到我与 Microsoft.Bcl.Async 的所有者一起弄清楚为什么会发生这种情况)是从 packages\Microsoft.Bcl.Async.1.0 复制 Microsoft.Threading.Tasks.Extensions.Desktop。 165\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll 到您的 BIN 文件夹。它应该可以解决这个问题。

    更新(3 月 17 日): 考虑将以下 Post-build 事件添加到您的项目中:

    复制 /Y "$(SolutionDir)packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll" "$(TargetDir)Microsoft.Threading.Tasks. Extensions.Desktop.dll"

    很遗憾,Bcl.Async 包的所有者还没有解决这个问题的方法。

    【讨论】:

      【解决方案4】:

      这种方法没有解决问题 - 我遇到了同样的运行时错误。但是在重建之后,我注意到 VS2013 编译器显示了这个警告,我为 SO 编辑器稍微格式化了一些

      C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning
      MSB3247: Found conflicts between different versions of the same dependent assembly. In Visual 
      Studio, double-click this warning (or select it and press Enter) to fix the conflicts; 
      otherwise, add the following binding redirects to the "runtime" node in the application 
      configuration file:
      
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
              <assemblyIdentity name="Microsoft.Threading.Tasks.Extensions.Desktop" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
              <bindingRedirect oldVersion="0.0.0.0-1.0.165.0" newVersion="1.0.165.0" />
          </dependentAssembly>
      </assemblyBinding>
      

      所以我在应用程序 web.config 文件中删除了建议的块。然后该应用程序决定工作。我不知道为什么它现在可以工作,但我的印象是您提到的 XML 块和/或参考修复以某种方式触及了 Microsoft.Threading.Tasks.Extensions.Desktop DLL 或 .Net 中的一些低级机制,或两者。或者都不是,据我所知。无论如何,谢谢你的帮助。我只希望我对内部机制有更好的了解。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多