.net ExternalSigninAsync MissingMethodException System.Threading.tasks

时间:2016-04-21 14:25:43

标签: c# .net multithreading asynchronous

我正试图通过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做了。

我为原始版本获取了大量日志,其中一些版本中存在失败。但是我认为这个网站确实已经建成了,所以这些绝不是致命的失败。但是当我真正尝试登录时,我只有几个日志,所有这些操作都是成功的。 Log Files sorted by Date

enter image description here

我不会列出完整的融合日志,但这里是一个从未成功绑定原始版本的程序集列表:

  • Microsoft.VisualStudio.Web.PageInspector.Runtime
  • iisexpresstray.resources

其中任何一个都会导致此错误吗?

更新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文件夹。

Current Visual Studio and NuGet version

更新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 Yarlaggadda要求查看我的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人代表了他们。我最后只是从头开始制作一个新网站并在那里移动我的内容。

1 个答案:

答案 0 :(得分:1)

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引用。如果解决方案中的所有项目都不引用相同的包版本和目标框架,则会发生各种奇怪的事情。检查所有这些!