najam83/CRSBugs — Issue #1: Editting staff member will throw exception if role is not changed
Author: najam83
Created: 2011-10-24 06:06:39+00:00
State: open

Cause:
I have to check code for roles stuff. And may be i m loading user from db that is tracked and then posted back thing is also attached to context.

Server Error in '/' Application.

AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.

Source Error:

Line 42: foreach (var role in user.Roles)
Line 43: {
Line 44: context.Entry(role).State = EntityState.Modified;
Line 45: }
Line 46: }

Source File: E:\work\aspnetLearning\MCVProjects\CSR\CRS\CRS.Domain\Models\UserRepository.cs Line: 44

Stack Trace:

[InvalidOperationException: AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.]
System.Data.Objects.ObjectStateManager.FixupKey(EntityEntry entry) +8116381
System.Data.Objects.EntityEntry.AcceptChanges() +98
System.Data.Objects.EntityEntry.ChangeObjectState(EntityState requestedState) +118
System.Data.Objects.EntityEntry.ChangeState(EntityState state) +94
System.Data.Entity.Internal.StateEntryAdapter.ChangeState(EntityState state) +15
System.Data.Entity.Internal.InternalEntityEntry.set_State(EntityState value) +96
CRS.Domain.Models.UserRepository.InsertOrUpdate(User user) in E:\work\aspnetLearning\MCVProjects\CSR\CRS\CRS.Domain\Models\UserRepository.cs:44
CRS.Areas.admin.Controllers.UsersController.Edit(RegisterModelEdit user) in E:\work\aspnetLearning\MCVProjects\CSR\CRS\CRS\Areas\admin\Controllers\UsersController.cs:171
lambda_method(Closure , ControllerBase , Object[] ) +108
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
Castle.Proxies.ControllerActionInvokerProxy.InvokeActionMethod_callback(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
Castle.Proxies.Invocations.ControllerActionInvoker_InvokeActionMethod.InvokeMethodOnTarget() +154
Castle.DynamicProxy.AbstractInvocation.Proceed() +56
Glimpse.Mvc3.Interceptor.InvokeActionMethodInterceptor.Intercept(IInvocation invocation) +336
Castle.DynamicProxy.AbstractInvocation.Proceed() +94
Castle.Proxies.ControllerActionInvokerProxy.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +214
System.Web.Mvc.<>c__DisplayClass15.b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.b__d() +50
System.Web.Mvc.SecurityUtil.b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862381
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184