2014-01-11 55 views
18

我想使用OAuth2和.Net 4.5框架构建Google BigQuery C#ASP.net应用程序。我跑这些的NuGet安装ASP.net应用程序崩溃 - 无法加载文件或程序集'Microsoft.Threading.Tasks.Extensions.Desktop'

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 

,我放置在相关的“usings”代码隐藏文件“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" 
       } 
      ); 
     } 
    } 
} 

我设置特定页面作为项目起始页。我拿起“已安装的应用”当我建立的客户ID文件在谷歌控制台

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

,我确信我添加文件(的client_secrets.json)在VS2013的解决方案资源管理器。在代码隐藏方面,我确信我已正确映射到Server.MapPath的client_secrets文件。对于凭证机构,我使用此代码

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

作为起点。当我运行的应用程序,它返回一个与

无法加载文件或程序集Microsoft.Threading.Tasks.Extensions.Desktop启动浏览器错误页,版本= 1.0.16.0,文化=中立,公钥= b03f5f7f11d50a3a'或它的一个依赖关系。该系统找不到指定的文件。

并在“凭证=”行崩溃。我试图添加一些实际的ASP.net崩溃的浏览器页面的图像,显​​示程序集加载跟踪/堆栈跟踪/等,但它看起来像我没有这个帐户权限。当我在“证书=”行设置一个断点,然后通过

DEBUG -> Start Debugging 
在VS2013

运行应用程序,网页停止在“证书=”线和一个文件选择器打开,寻找文件

"GoogleClientSecrets.cs" 

从目录

“C:\代码\ google.com \谷歌API-DOTNET客户端\ DEFAULT \工具\ Google.Apis.Release \ BIN \调试\输出\ DEFAULT \ SRC \ GoogleApis.Auth \ OAuth2 \ GoogleClientSecrets.cs“

这是无处在驱动器上。在生成的ASP.net错误页面中使用Assembly Load Trace,我尝试了解建议的配置文件,但没有任何工作。更一般地说,我试着在StackOverflow中寻找这个问题,虽然我找到了一些提及它的东西,但没有一个材料有帮助。

回答

29

因为错误是基于一个事实,即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)。
我使用.NET 4.5框架在VS2013上测试了它,它工作正常。

+0

你好。对不起,延迟。我试过你的建议,它的工作原理。谢谢你的帮助! - Frank –

3

我以前已经遇到过这个错误。它看起来像Bcl.Async包中包含一个引用到Microsoft.Threading.Tasks.Extensions.Desktop当您运行一个.NET 4.0应用程序,但不知何故它在.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文件夹中。它应该解决这个问题。

UPDATE(3月17日): 考虑加入以下生成后事件到您的项目:

复制/ Y“$(SolutionDir)包\ Microsoft.Bcl.Async.1.0.16 \ LIB \ net40 \ Microsoft.Threading.Tasks.Extensions.Desktop.dll” “$(TARGETDIR)Microsoft.Threading.Tasks.Extensions.Desktop.dll”

不幸的是,不是这个问题的解决方案尚未来自Bcl.Async软件包的所有者。

+0

为我工作。谢谢 – Manu

2

这种做法并没有解决这个问题 - 我得到了同样的运行时错误。但重建后,我注意到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中的一些底层机器,或两者。或者,既然我知道。无论如何,感谢您的帮助。我只希望我对内部机器有更好的了解。

+0

我联系了NuGet软件包的所有者,希望我们很快会找到更好的解决方案。 – peleyal

+0

显然1.0.166(https://www.nuget.org/packages/Microsoft.Bcl.Async/1.0.166-beta)修正了这个问题。 – peleyal

4

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

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

我希望它适合你。

+0

要非常清楚:安装google API nuget包,然后添加当前的Microsoft.Bcl.Async,它将替换Google包引用的 – Guillaume

相关问题