我想使用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中寻找这个问题,虽然我确实找到了一些关于它的提及,但这些材料都没有帮助。
发布于 2014-02-25 23:13:42
他们发布了新版本的-Package Microsoft.Bcl.Async。
如果有人遇到此问题,请安装“最新”版本,而不是1.0.16。
我希望它能为你工作。
发布于 2014-01-12 00:46:10
我以前已经遇到过这个错误。在运行.NET 4.0应用程序时,Bcl.Async包似乎包含了对Microsoft.Threading.Tasks.Extensions.Desktop的引用,但在.NET 4.5应用程序中却不知何故丢失了它。
我给你的建议(直到我弄清楚为什么会发生)是从packages\Microsoft.Bcl.Async.1.0.165\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll复制Microsoft.Bcl.Async到你的Microsoft.Threading.Tasks.Extensions.Desktop文件夹。它应该可以解决这个问题。
更新(3月17日):考虑将以下Post-build事件添加到您的项目中:
"$(SolutionDir)packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll“"$(TargetDir)Microsoft.Threading.Tasks.Extensions.Desktop.dll”的
copy /Y
不幸的是,Bcl.Async包的所有者还没有针对这个问题的解决方案。
发布于 2014-01-12 07:15:44
这种方法没有解决这个问题--我得到了同样的运行时错误。但是在重新构建之后,我注意到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中的一些低级机制,或者两者兼而有之。或者都不是,就我所知。不管怎样,谢谢你的帮助。我只希望我对内部机制有更好的理解。
https://stackoverflow.com/questions/21057052
复制相似问题