Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

Vote:
 

I have a property in a block and an interesting problem appeared after another developer made some changes to the block and view.

public virtual Url ImageUrl { get; set; }

When I run the code I get this error because we have changed the view to expect a ContentReference.

Server Error in '/' Application.

The model item passed into the dictionary is of type 'EPiServer.Url', but this dictionary requires a model item of type 'EPiServer.Core.ContentReference'.

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: The model item passed into the dictionary is of type 'EPiServer.Url', but this dictionary requires a model item of type 'EPiServer.Core.ContentReference'.

Source Error:


[No relevant source lines]

Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\993dd59c\c149002a\App_Web_awbcdqks.9.cs Line: 0

Stack Trace:


[InvalidOperationException: The model item passed into the dictionary is of type 'EPiServer.Url', but this dictionary requires a model item of type 'EPiServer.Core.ContentReference'.]
System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +383
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +625
System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData) +74
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +137
System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions) +870
System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate) +1371
System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData) +107
System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData) +155
System.Web.Mvc.Html.DisplayExtensions.DisplayFor(HtmlHelper`1 html, Expression`1 expression, String templateName) +108
EPiServer.Web.Mvc.Html.<>c__DisplayClass5`2.<GetHtmlForEditMode>b__0(StringWriter writer) +23
EPiServer.Web.Mvc.Html.PropertyRenderer.CreateMvcHtmlString(Action`1 action) +67
EPiServer.Web.Mvc.Html.PropertyRenderer.PropertyFor(HtmlHelper`1 html, String viewModelPropertyName, Object additionalViewData, Object editorSettings, Expression`1 expression, Func`2 displayForAction) +566
EPiServer.Web.Mvc.Html.PropertyExtensions.PropertyFor(HtmlHelper`1 html, Expression`1 expression) +485
ASP._Page_Views_Shared_HeroHeaderViewOne_cshtml.Execute() in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\993dd59c\c149002a\App_Web_awbcdqks.9.cs:0
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName, Object model) +116
ASP._Page_Views_Shared_HeroHeader_cshtml.Execute() in c:\EPiServer\Sogeti2014\wwwroot\Views\Shared\HeroHeader.cshtml:10
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName, Object model) +116
ASP._Page_Views_StartPage_StartPage_cshtml.Execute() in c:\EPiServer\Sogeti2014\wwwroot\Views\StartPage\StartPage.cshtml:4
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
System.Web.WebPages.StartPage.ExecutePageHierarchy() +143
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +181
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +855148
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +855148
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +855148
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +855148
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +855148
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +855148
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +855148
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +839620
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446

Changing the property to a ContentRefernce gives a new error which I believe to be a bug in EPiServer. Only by undoing the change can I get my site to function again.
Otherwise it is completely dead and the only way we have figured out how to get it back runing again was making a new database. If anyone knows a better way please let me know.
I am going to investigate this but since I find nothing about this issue I thought I would start a thread on world.

public virtual ContentReference ImageUrl { get; set; }

The new error:

Server Error in '/' Application.

Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

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.Data.DBConcurrencyException: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

Source Error:


[No relevant source lines]

Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\993dd59c\c149002a\App_global.asax.0.cs Line: 0

Stack Trace:


[DBConcurrencyException: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.]
System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +2319164
System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +75
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) +3479
System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping) +66
System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) +370
EPiServer.DataAccess.PropertyDefinitionDB.ConvertDataType(Int32 id, PropertyDataType fromType, PropertyDefinitionType propertyType) +2151
EPiServer.DataAccess.<>c__DisplayClass13.<SaveToDb>b__12() +3592
EPiServer.Data.Providers.<>c__DisplayClass7`1.<ExecuteTransaction>b__6() +231
EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute(Func`1 method) +150
EPiServer.DataAccess.PropertyDefinitionDB.Save(PropertyDefinition propertyDefinition) +393
EPiServer.DataAbstraction.DefaultPropertyDefinitionRepository.Save(PropertyDefinition propertyDefinition, Boolean forceCacheClear) +237
EPiServer.DataAbstraction.RuntimeModel.PropertyDefinitionSynchronizer.UpdatePropertyDefinition(PropertyDefinitionModel model) +213
EPiServer.DataAbstraction.RuntimeModel.ContentTypeModelRegister.CommitProperties(Boolean deleteUnusedTypes) +429
EPiServer.DataAbstraction.RuntimeModel.ContentTypeModelScanner.Sync(Boolean commitChanges) +302
EPiServer.Initialization.ModelSyncInitialization.Initialize(InitializationEngine context) +387
EPiServer.Framework.Initialization.ModuleNode.Execute(Action a, String key) +64
EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +719
EPiServer.Framework.Initialization.InitializationEngine.Initialize(HostType hostType) +168
EPiServer.Framework.Initialization.InitializationModule.Initialize(HostType hostType) +285
EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType) +104
EPiServer.Global..ctor() +110
Sogeti2014.Global..ctor() +40
ASP.global_asax..ctor() in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\993dd59c\c149002a\App_global.asax.0.cs:0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +159
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +256
System.Activator.CreateInstance(Type type, Boolean nonPublic) +127
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) +14259449
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +200
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +28
System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +83
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +312
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12968244
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12807949

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446

#86241
May 16, 2014 12:47
Vote:
 

I solved my problem by removing the [CultureSpecific] attribute.

My property looked like this:

[UIHint(UIHint.Image)]
[CultureSpecific]
[Display(
Name = "Image",
Description = "Name field's description",
Order = 10)]
public virtual Url ImageUrl { get; set; }

I changed it to this:

[Display(
Name = "Image",
Description = "Name field's description",
Order = 10)]
public virtual ContentReference ImageUrl { get; set; }

And my site worked again. Only then could I add the attribute again.

#86242
Edited, May 16, 2014 13:08
Vote:
 

Interesting, this error still occurs 1,5 years later. Thanks for the solution!

#142190
Dec 04, 2015 10:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.