![](/img/trans.png)
[英]Could not load file or assembly 'Microsoft.Threading.Tasks.Extensions.Desktop' or one of its dependencies. The parameter is incorrect
[英]ASP.net app crashes - Could not load file or assembly '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
我在代码隐藏文件“default.aspx.cs”中放置了相关的“usings”:
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:\\代码\\ google.com \\谷歌API-DOTNET客户端\\ DEFAULT \\工具\\ Google.Apis.Release \\ BIN \\调试\\输出\\ DEFAULT \\ SRC \\ GoogleApis.Auth \\的OAuth2 \\ GoogleClientSecrets.cs”
这是无处可去的。 在生成的ASP.net错误页面中使用程序集加载跟踪,我尝试了解建议的配置文件但没有任何效果。 更一般地说,我尝试在StackOverflow中寻找这个问题,虽然我确实发现了一些提及它,但这些材料都没有帮助。
因为错误是基于最新版本的Microsoft.Bcl.Async在.NET 4.5中不起作用的事实,您可以尝试执行以下操作:
打开Package Manager控制台,然后运行以下命令:
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上测试它,它的工作原理。
他们发布了新版本的-Package Microsoft.Bcl.Async。
如果有人遇到此问题,请安装“最新”版本而不是1.0.16。
我希望这个对你有用。
我之前已经遇到过这个错误。 看起来Bcl.Async包在运行.NET 4.0应用程序时包含对Microsoft.Threading.Tasks.Extensions.Desktop的引用,但在.NET 4.5应用程序中却不知何故。
我给你的建议(直到我将我们与Microsoft.Bcl.Async的所有者联系起来,为什么会这样)是从packages \\ Microsoft.Bcl.Async.1.0.165 \\ lib复制Microsoft.Threading.Tasks.Extensions.Desktop \\ net40 \\ Microsoft.Threading.Tasks.Extensions.Desktop.dll到你的BIN文件夹。 它应该解决这个问题。
更新(3月17日):考虑将以下Post-build事件添加到您的项目中:
copy / 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包的所有者还没有针对这个问题的解决方案。
这种方法没有解决问题 - 我得到了相同的运行时错误。 但是在重建之后,我注意到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>
所以我在app web.config文件中删除了建议的块。 然后应用程序决定工作。 我不知道为什么它现在可以工作,但我得到的印象是你提到的XML块和/或引用修补程序以某种方式触及了Microsoft.Threading.Tasks.Extensions.Desktop DLL,或.Net中的一些低级机制,或两者。 或者两者都不知道。 无论如何,谢谢你的帮助。 我只希望我对内部机器有更好的了解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.