[英].net ExternalSigninAsync MissingMethodException System.Threading.tasks
我正在嘗試通過 Google 將用戶登錄到我的網站。 Google 登錄工作正常,但我在行上的 AccountController 方法中收到 MissingMethodException:
var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
錯誤是:
Method not found: 'System.Threading.Tasks.Task`1<!!0> System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(System.Linq.IQueryable`1<!!0>, System.Linq.Expressions.Expression`1<System.Func`2<!!0,Boolean>>)'.
我曾嘗試在 AccountController 中使用 System.Threading.Tasks。 我還尋找了其他可以使用 System.Threading.Tasks 的地方,並試圖將它放在那里。
問題:是什么導致了此錯誤,如何修復?
這是包含該行的整個方法:
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
// Sign in the user with this external login provider if the user already has a login
var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
case SignInStatus.Failure:
default:
// If the user does not have an account, then prompt the user to create an account
ViewBag.ReturnUrl = returnUrl;
ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
}
}
更新根據幾位評論者的建議,我一直試圖找出 Fusion Log 發生了什么,但仍然無法找到它。 具體來說,我做了以下事情:我在 FusionLog 注冊表中將 ForceLog 和 LogFailures 設置為 1,並給它一個目錄。 然后我在 11:59 建立了網站,然后等了幾分鍾才嘗試登錄 Google,我在 12:03 登錄。
我得到了大量原始構建的日志,其中一些有故障。 但該網站確實建立了,所以我認為那些一定不是致命的失敗。 但是當我真正嘗試登錄時,我只得到了一些日志,所有這些操作都成功了。
我不會列出完整的融合日志,但這里有一個從未成功綁定到原始版本的程序集列表:
這些中的任何一個都可能導致此錯誤嗎?
更新 2查看其他日志,我認為 WebpageInspector.Runtime 最終確實成功綁定。 唯一從未發生過的事情是 iisexpresstray.resources,但根據有關 Fusion Log 的博客,我讀到:“除非您明確調試資源加載失敗,否則您可能希望忽略查找具有“.resources”擴展名,文化設置為“中性”以外的其他內容。當 ResourceManager 探測附屬程序集時,這些是預期的失敗。” 所以現在我真的不知道失敗是什么。
更新 3其他不起作用的事情
更新 4 Mike Barry 告訴我 .net40 不能進行異步操作,所以如果我的任何引用引用了文件的 .net40 版本,那么它就無法工作。 我認為我的 EntityFramework 指的是 .net 40 版本的文件,因為它所指的文件夾是[PROJECT PATH]\\packages\\EntityFramework.6.1.3\\lib\\net40\\EntityFramework.dll
。 但無論我做什么,我都無法讓它引用[PROJECT PATH]\\packages\\EntityFramework.6.1.3\\lib\\net45\\EntityFramework.dll
。 我在我的屬性和 .csproj 文件中的所有引用都引用了 .net4.5,但是當我卸載並重新安裝 EntityFramework 時,它頑固地返回到 .net40 文件夾。
更新 5
我使用 try-catch 來獲取有關異常的所有信息。 這是我得到的:
Exception System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<!!0> System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(System.Linq.IQueryable`1<!!0>, System.Linq.Expressions.Expression`1<System.Func`2<!!0,Boolean>>)'.
at Microsoft.AspNet.Identity.EntityFramework.UserStore`6.<FindAsync>d__23.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.AspNet.Identity.EntityFramework.UserStore`6.FindAsync(UserLoginInfo login)
at Microsoft.AspNet.Identity.UserManager`2.FindAsync(UserLoginInfo login)
at Microsoft.AspNet.Identity.Owin.SignInManager`2.<ExternalSignInAsync>d__1d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at LangSite_151209.Controllers.AccountController.<ExternalLoginCallback>d__3a.MoveNext() in c:\Users\Administrator\Source\Workspaces\Lang Site 4.12\DEV\Controllers\AccountController.cs:line 342
data = System.Collections.ListDictionaryInternal
helplink =
hrresult = -2146233069
innerexception =
message = Method not found: 'System.Threading.Tasks.Task`1<!!0> System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(System.Linq.IQueryable`1<!!0>, System.Linq.Expressions.Expression`1<System.Func`2<!!0,Boolean>>)'.
source = Microsoft.AspNet.Identity.EntityFramework
stacktrace = at Microsoft.AspNet.Identity.EntityFramework.UserStore`6.<FindAsync>d__23.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.AspNet.Identity.EntityFramework.UserStore`6.FindAsync(UserLoginInfo login)
at Microsoft.AspNet.Identity.UserManager`2.FindAsync(UserLoginInfo login)
at Microsoft.AspNet.Identity.Owin.SignInManager`2.<ExternalSignInAsync>d__1d.MoveNext()
Soma Yarlagadda 要求查看我的packages.config,所以它是:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net451" />
<package id="EntityFramework" version="6.1.3" targetFramework="net451" />
<package id="jQuery" version="2.2.3" targetFramework="net451" />
<package id="jQuery.Validation" version="1.15.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.1" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.Owin" version="2.2.1" targetFramework="net451" />
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net451" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net451" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Security.Facebook" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Security.Google" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Security.MicrosoftAccount" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Security.Twitter" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net451" />
<package id="Modernizr" version="2.8.3" targetFramework="net451" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net451" />
<package id="Owin" version="1.0" targetFramework="net451" />
<package id="Respond" version="1.4.2" targetFramework="net451" />
<package id="WebGrease" version="1.6.0" targetFramework="net451" />
</packages>
最終更新:從來沒有解決這個問題。 50 代表下水道的賞金。 我最終只是從頭開始創建一個新網站並將我的內容移到那里。
nuget 包中的實體框架 4.0 dll 不包含 FirstOrDefaultAsync 方法,因為 .NET 4.0 沒有對 async 和 await 的本機支持。 只有 nuget 包中的 4.5 dll 具有方法調用。 底線:確保解決方案中的所有項目都是為 .NET 4.5 構建的,並且它們都引用了 nuget 包的 4.5 dll 文件夾。
如果之前的項目是 4.0,並且將其升級到 4.5,則 nuget 引用不會修改到 4.5 文件夾。 如果您有另一個 4.0 項目並且仍然引用 4.0 dll,則對 4.0 dll 的引用可以在構建時覆蓋 4.5 引用。 如果解決方案中的所有項目不引用相同的包版本和目標框架,就會發生各種奇怪的事情。 檢查所有這些!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.