2016-04-21 261 views
2

我正尝试通过Google将用户登录到我的网站。该谷歌登入正常工作,但我在上线的AccountController方法得到一个MissingMethodException:.net ExternalSigninAsync MissingMethodException System.Threading.tasks

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登录,但我仍然无法找到的意见它。具体来说,我做了以下工作:我在FusionLog注册表中将ForceLog和LogFailures设置为1,并给它一个目录。然后我在11:59建立了网站,然后等了几分钟才尝试登录谷歌,我在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的博客,我读到:“除非你明确地调试资源加载失败,否则你可能会忽略找到具有“文件”扩展的文化设置为“中性”以外的内容,当ResourceManager探测附属程序集时,这些预计会失败。所以现在我真的不知道失败是什么。

更新3分 没有工作

  • 重新安装所有的包
  • 清洗和重建解决方案

更新4 迈克·巴里告诉我,其他的事情。 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() 

索玛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代表为赏金而流失。我最终只是从头开始创建一个新网站,并在那里移动我的内容。

+0

您的网站是否正确部署?特别是,与开发环境相同版本的“EntityFramework.dll”(定义了这种扩展方法)? –

+0

好问题;它似乎不是!我使用.net 4.5,看起来我有.net 4.0的EntityFramework;该文件是\ packages \ EntityFramework.6.1.3 \ lib \ net40 \ EntityFramework.dll。这可能是问题所在。你知道如何改变这个吗? – jimboweb

+0

[Entity Framework 6.1.3支持此方法](https://msdn.microsoft.com/library/system.data.entity.queryableextensions.firstordefaultasync),因此特定版本不是您的问题。除了连接调试器/打开融合日志记录以及查看在运行时加载的程序集版本,我没有进一步的建议。 –

回答

0

nuget包中的实体框架4.0 dll不包含FirstOrDefaultAsync方法,因为.NET 4.0没有本地支持异步和等待。只有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的引用就可以在构建时覆盖4.5的引用。如果解决方案中的所有项目都没有引用相同的软件包版本和目标框架,则会发生各种奇怪的事情。检查所有的人!

+0

我认为我的问题是与EntityFramework,因为我认为它仍然指的是4.0版本。这很难说,但对象浏览器告诉我EF的文件夹是'[sitepath] \ packages \ EntityFramework.6.1.3 \ lib \ net40 \ EntityFramework.dll'。那'net40'暗示它指的是错误的。然而,无论我做什么,我似乎都无法改变它。 – jimboweb

+0

我的项目的目标框架被设置为.net框架4.5.1,我的csproj文件说同样的事情。在.csproj文件中对EntityFramework的引用是'packages \ EntityFramework.6.1.3 \ lib \ net45 \ EntityFramework.dll'。我曾尝试使用软件包管理器来卸载并重新安装EF,但我仍然以相同的目录结束。如何改变NuGet对.net 40版本的顽固坚持? – jimboweb

+0

什么版本的visual studio和nuget扩展? –

相关问题