简体   繁体   English

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

[英]ASP.net app crashes - Could not load file or assembly 'Microsoft.Threading.Tasks.Extensions.Desktop'

I want to build a Google BigQuery C# ASP.net application using OAuth2 and the .Net 4.5 framework. 我想使用OAuth2和.Net 4.5框架构建一个Google BigQuery C#ASP.net应用程序。 I ran these NuGet installs 我运行了这些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

and I placed the relevant "usings" in code-behind file "default.aspx.cs": 我在代码隐藏文件“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"
                }
            );
        }
    }
}

I set this specific page as the project start page. 我将此特定页面设置为项目开始页面。 I picked "Installed application" when I built the Client ID file at the Google console 当我在Google控制台上构建客户端ID文件时,我选择了“已安装的应用程序”

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

and I made sure I added this file (client_secrets.json) with the solution explorer in VS2013. 我确保在VS2013中使用解决方案资源管理器添加了此文件(client_secrets.json)。 In the code-behind, I made sure that I correctly mapped to the client_secrets file with Server.MapPath. 在代码隐藏中,我确保使用Server.MapPath正确映射到client_secrets文件。 For the credential machinery, I used this code 对于凭证机制,我使用了这段代码

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

as the starting point. 作为起点。 When I run the app, it returns a browser error page that starts with 当我运行应用程序时,它会返回一个以...开头的浏览器错误页面

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. 无法加载文件或程序集“Microsoft.Threading.Tasks.Extensions.Desktop,Version = 1.0.16.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a”或其依赖项之一。 The system cannot find the file specified. 该系统找不到指定的文件。

and crashes at the "credential =" line. 并在“credential =”行崩溃。 I tried to add in some images of the actual ASP.net crashed browser page showing the Assembly Load Trace / Stack Trace / etc. but it looks like I don't have the account rights for this. 我试图添加一些实际ASP.net崩溃浏览器页面的图像,显​​示程序集加载跟踪/堆栈跟踪/等等,但看起来我没有此帐户权限。 When I set a breakpoint at the "credential =" line and then run the app through 当我在“credential =”行设置断点然后运行应用程序时

DEBUG -> Start Debugging

in VS2013, the page stops at the "credential =" line and a file picker opens, looking for file 在VS2013中,页面停在“credential =”行,文件选择器打开,查找文件

"GoogleClientSecrets.cs"

from directory 来自目录

"c:\\code\\google.com\\google-api-dotnet-client\\default\\Tools\\Google.Apis.Release\\bin\\Debug\\output\\default\\Src\\GoogleApis.Auth\\OAuth2\\GoogleClientSecrets.cs" “C:\\代码\\ google.com \\谷歌API-DOTNET客户端\\ DEFAULT \\工具\\ Google.Apis.Release \\ BIN \\调试\\输出\\ DEFAULT \\ SRC \\ GoogleApis.Auth \\的OAuth2 \\ GoogleClientSecrets.cs”

which is nowhere on the drive. 这是无处可去的。 Using the Assembly Load Trace in the generated ASP.net error page, I tried digging around through the suggested configuration files but nothing worked. 在生成的ASP.net错误页面中使用程序集加载跟踪,我尝试了解建议的配置文件但没有任何效果。 More generally, I tried looking for this issue in StackOverflow and while I did find some mention of it, none of that material helped. 更一般地说,我尝试在StackOverflow中寻找这个问题,虽然我确实发现了一些提及它,但这些材料都没有帮助。

Because the error is based on the fact that the latest version of Microsoft.Bcl.Async doesn't work in .NET 4.5, you can try to do the following: 因为错误是基于最新版本的Microsoft.Bcl.Async在.NET 4.5中不起作用的事实,您可以尝试执行以下操作:

Open your Package Manager Console, and run the following commands: 打开Package Manager控制台,然后运行以下命令:
1) Uninstall-Package Microsoft.Bcl.Async -Force 1)卸载 - 打包Microsoft.Bcl.Async -Force
2) Install-Package Microsoft.Bcl.Async -Version 1.0.16 2)安装包Microsoft.Bcl.Async -Version 1.0.16

It works in a sample I'm currently writing. 它适用于我目前正在编写的一个示例。 Please let me know if it works for you. 如果它适合您,请告诉我。

UPDATE (March 21st): You can update the package (new version 1.0.166-beta is available - https://www.nuget.org/packages/Microsoft.Bcl.Async/1.0.166-beta ). 更新(3月21日):您可以更新软件包(新版本1.0.166-beta可用 - https://www.nuget.org/packages/Microsoft.Bcl.Async/1.0.166-beta )。
I tested it on VS2013 with .NET 4.5 framework and it works. 我使用.NET 4.5框架在VS2013上测试它,它的工作原理。

They released a new version of -Package Microsoft.Bcl.Async. 他们发布了新版本的-Package Microsoft.Bcl.Async。

If somebody has this issue, please install the "latest" version instead of 1.0.16. 如果有人遇到此问题,请安装“最新”版本而不是1.0.16。

I hope it works for you. 我希望这个对你有用。

I already encountered this error before. 我之前已经遇到过这个错误。 It looks like the Bcl.Async package contains a reference to Microsoft.Threading.Tasks.Extensions.Desktop when you run a .NET 4.0 applications but somehow it is missing in .NET 4.5 application. 看起来Bcl.Async包在运行.NET 4.0应用程序时包含对Microsoft.Threading.Tasks.Extensions.Desktop的引用,但在.NET 4.5应用程序中却不知何故。

My advice for you (until I'll figure our with the owner of Microsoft.Bcl.Async why it happens) is to copy Microsoft.Threading.Tasks.Extensions.Desktop from packages\\Microsoft.Bcl.Async.1.0.165\\lib\\net40\\Microsoft.Threading.Tasks.Extensions.Desktop.dll to your BIN folder. 我给你的建议(直到我将我们与Microsoft.Bcl.Async的所有者联系起来,为什么会这样)是从packages \\ Microsoft.Bcl.Async.1.0.165 \\ lib复制Microsoft.Threading.Tasks.Extensions.Desktop \\ net40 \\ Microsoft.Threading.Tasks.Extensions.Desktop.dll到你的BIN文件夹。 It should solve this issue. 它应该解决这个问题。

UPDATE (March 17th): Consider adding the following Post-build event to your project: 更新(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" 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”

Unfortunately, there isn't a solution for this problem yet from the owners of the Bcl.Async package. 不幸的是,Bcl.Async包的所有者还没有针对这个问题的解决方案。

This approach did not fix the issue - I got the same runtime error. 这种方法没有解决问题 - 我得到了相同的运行时错误。 But after a rebuild, I noticed that the VS2013 compiler showed this warning, which I formatted a little for the SO editor 但是在重建之后,我注意到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>

so I dropped the suggested block in the app web.config file. 所以我在app web.config文件中删除了建议的块。 Then the app decided to work. 然后应用程序决定工作。 I have no idea why it works now, but I get the impression that the XML block and / or the reference fix you mentioned somehow touched the Microsoft.Threading.Tasks.Extensions.Desktop DLL, or some low-level machinery inside .Net, or both. 我不知道为什么它现在可以工作,但我得到的印象是你提到的XML块和/或引用修补程序以某种方式触及了Microsoft.Threading.Tasks.Extensions.Desktop DLL,或.Net中的一些低级机制,或两者。 Or neither, for all I know. 或者两者都不知道。 Anyway, thanks for your help. 无论如何,谢谢你的帮助。 I only wish I had a better understanding of the internal machinery. 我只希望我对内部机器有更好的了解。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集“ Microsoft.Threading.Tasks.Extensions.Desktop”或其依赖项之一。 参数不正确 - Could not load file or assembly 'Microsoft.Threading.Tasks.Extensions.Desktop' or one of its dependencies. The parameter is incorrect 无法加载文件或程序集-ASP.NET MVC应用 - Could not load file or assembly - asp.net mvc app ASP.net无法加载文件或程序集 - ASP.net Could not load file or assembly 无法加载文件或程序集asp.net - Could not load file or assembly asp.net 无法在生产ASP.net网站上加载文件或程序集Microsoft.SqlServer.SqlClrProvider,它在哪里? - Could not load file or assembly Microsoft.SqlServer.SqlClrProvider on production ASP.net site, where is it? 在ASP.NET SQL Server 2014 Express中获得错误“无法加载文件或程序集microsoft.sqserver…” - Get error “could not load file or assembly microsoft.sqserver…” in ASP.NET SQL Server 2014 Express ASP.NET部署失败-无法加载文件或程序集“ Microsoft.mshtml” - ASP.NET Deployment Fails - Could not load file or assembly 'Microsoft.mshtml' ASP.NET损坏程序集“无法加载文件或程序集App_Web_ *” - ASP.NET corrupt assembly “Could not load file or assembly App_Web_*” 无法加载文件或程序集&#39;file:/// C:\\ WINDOWS \\ Microsoft.NET \\ Framework \\ v4.0.30319 \\ asp.net vs2010 - Could not load file or assembly 'file:///C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\ asp.net vs2010 无法使用预编译的ASP.NET网站项目加载文件或程序集App_Web_ * - Could not load file or assembly App_Web_ * with a precompiled ASP.NET website project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM