簡體   English   中英

ASP.net應用程序崩潰 - 無法加載文件或程序集'Microsoft.Threading.Tasks.Extensions.Desktop'

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM