I posted this question on stack overflow, but to no avail. Getting desperate here.
So we have an extremely random error (by which I mean, there appears to be no usage pattern that precedes the error) in our C# ASP.NET MVC5 application, that occurs in our production environment.
The error appears to occur only sometimes after a user logs in, and the entire system crashes and becomes inaccessible to all users until we manually go into IIS8 and restart the web server. We are running SQL Server Express 2012 SP2 on a windows server 2012 environment with IIS.
The error message as follows:
IndexOutOfRangeException/Account/Login
Index was outside the bounds of the array.
The stack trace is as follows:
IndexOutOfRangeException·Index was outside the bounds of the array.
Raw
:0System.Data.SqlClient.SqlDataReader.CheckHeaderIsReady(Int32 columnIndex, Boolean permitAsync, String methodName)
:0System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i)
:0System.Data.Entity.Core.Common.Internal.Materialization.Shaper+ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
:0lambda_method(Closure , Shaper )
:0System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
:0lambda_method(Closure , Shaper )
:0System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
:0System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1+SimpleEnumerator+<MoveNextAsync>d__4.MoveNext()
:0System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
:0System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
:0System.Data.Entity.Internal.LazyAsyncEnumerator`1+<FirstMoveNextAsync>d__0.MoveNext()
:0System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
:0System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
:0System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions+<FirstOrDefaultAsync>d__25`1.MoveNext()
:0System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
:0System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
:0Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1.GetResult()
:0Microsoft.AspNet.Identity.EntityFramework.UserStore`6+<GetUserAggregateAsync>d__6c.MoveNext()
:0System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
:0System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
:0Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1.GetResult()
:0Microsoft.AspNet.Identity.UserManager`2+<FindAsync>d__12.MoveNext()
:0System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
:0System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
:0Saleboat.Controllers.AccountController+<Login>d__9.MoveNext()
:0System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
:0System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
:0System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)
:0System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult)
:0System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
:0System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
:0System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
:0System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
:0System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
:0System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21+<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
:0System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
This error only occurs on our live server/database and cannot be intentionally reproduced, we pretty much have to wait for it to happen and review the exception caught by Bugsnag.
EDIT
Here is the code executed upon sign in:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null)
{
var userId = UserManager.FindByName(model.UserName).Id;
int companyId = db.Users.Find(userId).CompanyId;
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
return View(model);
}