ASP.net应用程序崩溃 – 无法加载文件或程序集“Microsoft.Threading.Tasks.Extensions.Desktop”

我想使用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

并将相关的“uses”放在代码隐藏文件“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>

为起点。当我运行应用程序,它返回一个浏览器错误页面开头

Could not load file or assembly ‘Microsoft.Threading.Tasks.Extensions.Desktop,Version=1.0.16.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.

并在“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错误页面中使用Assembly Load Trace,我尝试通过建议的配置文件挖掘,但没有任何工作。更一般来说,我试图在StackOverflow中寻找这个问题,而当我确实找到了一些提及的时候,没有一个帮助。

解决方法

因为错误是基于Microsoft.Bcl.Async的最新版本在.NET 4.5中不起作用的事实,您可以尝试执行以下操作:

打开您的软件包管理器控制台,并运行以下命令:
1)卸载 – 打包Microsoft.Bcl.Async -Force
2)Install-Package 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框架,它的工作原理。

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...