UserManager.Create: An exception of type 'System.MissingMethodException' occurred in mscorlib.dll but was not handled in user code

asp.net c# entity-framework-6

Question

I'm currently using Visual Studio Express 2013 for Web to create a website, and I'm using the built-in membership capability to allow visitors to sign up. But when I access the website on localhost and try to sign up a user, I get the following message:

An exception of type 'System.MissingMethodException' occurred in mscorlib.dll 
but was not handled in user code

Additional information: 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>>)'.

The stack trace from my browser is shown here:

[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>>)'.]
   Microsoft.AspNet.Identity.EntityFramework.UserStore`6.GetUserAggregateAsync(Expression`1 filter) +0
   Microsoft.AspNet.Identity.EntityFramework.UserStore`6.FindByNameAsync(String userName) +1071
   Microsoft.AspNet.Identity.UserManager`2.FindByNameAsync(String userName) +177
   Microsoft.AspNet.Identity.<ValidateUserName>d__4.MoveNext() +803
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
   Microsoft.AspNet.Identity.<ValidateAsync>d__0.MoveNext() +468
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +123
   Microsoft.AspNet.Identity.<CreateAsync>d__0.MoveNext() +795
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +123
   Microsoft.AspNet.Identity.<CreateAsync>d__d.MoveNext() +970
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.AspNet.Identity.AsyncHelper.RunSync(Func`1 func) +409
   Microsoft.AspNet.Identity.UserManagerExtensions.Create(UserManager`2 manager, TUser user, String password) +260
   Account_Register.CreateUser_Click(Object sender, EventArgs e) in c:\Users\Matthew\Documents\College\Senior\CSE 448\Capstone\Capstone\Account\Register.aspx.cs:14
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628026
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Stars indicate the line of code where the exception is being thrown:

protected void CreateUser_Click(object sender, EventArgs e)
    {
        var manager = new UserManager();
        var user = new ApplicationUser() { UserName = UserName.Text };

        *****IdentityResult result = manager.Create(user, Password.Text);
        if (result.Succeeded)
        {
            IdentityHelper.SignIn(manager, user, isPersistent: false);
            IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
        }
        else
        {
            ErrorMessage.Text = result.Errors.FirstOrDefault();
        }
    }

I've been looking for a solution for a while, but I can't seem to locate one. All of my references have been updated, but to no avail. Has this happened to anyone else?

1
2
11/29/2014 12:58:04 AM

Popular Answer

Got it! TheFirstOrDefaultAsync only the.Net 4.5 Entity Framework assemblies have extension methods. I have references to both.Net 4.0 and.Net 4.5 in various projects. as soon as I switched them all to. It could utilise the Net 4.5Async code.

5
1/29/2015 2:36:12 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow