November Happy Hour will be moved to Thursday December 5th.

SetDefaultValues: CategoryList

Vote:
 

I have used the override of SetDefaultValues many times with no problems to set values of properties. Now, however, I have a property which is a CategoryList and I get an error when I try to set it is SetDefaultValues. Error log reproduced below.

Anothe thing which is confusing me is that, when debugging this code, the method SetDefaultValues is called twice. As soon as I create the new page it is called. Then I am prompted for a name for the page, and the method is executed again. Why is this?

Thanks.

Error log:

2015-09-15 11:49:50,847 [9] ERROR EPiServer.Global: 1.2.5 Unhandled exception in ASP.NET
System.NotSupportedException: Invalid use of read-only object, call CreateWritableClone() to create a writable clone.
   at EPiServer.Data.Validator.ValidateNotReadOnly(IReadOnly readOnly)
   at EPiServer.Core.CategoryList.ThrowIfReadOnly()
   at EPiServer.Core.CategoryList.set_IsModified(Boolean value)
   at EPiServer.Core.PropertyCategory.set_IsModified(Boolean value)
   at EPiServer.DataAccess.ContentSaveDB.SaveContentVersionProperty(IContent content)
   at EPiServer.DataAccess.ContentSaveDB.CreateAndSave(IContent content, Boolean delayPublish, Boolean forceCurrentVersion, Boolean forceNewVersion, String currentUser)
   at EPiServer.DataAccess.ContentSaveDB.<>c__DisplayClass16.b__15()
   at EPiServer.Data.Providers.SqlDatabaseHandler.<>c__DisplayClass4.b__3()
   at EPiServer.Data.Providers.SqlDatabaseHandler.<>c__DisplayClass7`1.b__6()
   at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
   at EPiServer.Data.Providers.SqlDatabaseHandler.ExecuteTransaction[TResult](Func`1 action)
   at EPiServer.Data.Providers.SqlDatabaseHandler.ExecuteTransaction(Action action)
   at EPiServer.DataAccess.ContentSaveDB.SaveInternal(IContent content, SaveAction action, Nullable`1 delayPublishUntil, String currentUser)
   at EPiServer.DataAccess.ContentSaveDB.Save(IContent content, SaveAction action, String currentUser)
   at EPiServer.DataAbstraction.ContentStore.Save(IContent content, SaveAction action, String currentUser)
   at EPiServer.DefaultContentProvider.Save(IContent content, SaveAction action)
   at EPiServer.Core.DefaultContentRepository.Save(IContent content, SaveAction action, AccessLevel access)
   at EPiServer.IContentRepositoryExtension.Save(IContentRepository repository, IContent content, SaveAction action)
   at EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.CreateContent(ContentReference parentLink, Int32 contentTypeId, Nullable`1 resourceFolderId, Boolean createAsLocalAsset, String name, IDictionary`2 properties, SaveAction saveAction)
   at EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.Create(ContentReference parentLink, Int32 contentTypeId, Nullable`1 resourceFolderId, Boolean createAsLocalAsset, String name, IDictionary`2 properties, Boolean autoPublish)
   at EPiServer.Cms.Shell.UI.Rest.ContentDataStore.Post(PostContentModel entity)
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at EPiServer.Shell.Services.Rest.RestControllerBase.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at EPiServer.Shell.Services.Rest.RestHttpHandler.ProcessRequest(HttpContextBase httpContext)
   at EPiServer.Shell.Services.Rest.RestHttpHandler.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
System.NotSupportedException: Invalid use of read-only object, call CreateWritableClone() to create a writable clone.
   at EPiServer.Data.Validator.ValidateNotReadOnly(IReadOnly readOnly)
   at EPiServer.Core.CategoryList.ThrowIfReadOnly()
   at EPiServer.Core.CategoryList.set_IsModified(Boolean value)
   at EPiServer.Core.PropertyCategory.set_IsModified(Boolean value)
   at EPiServer.DataAccess.ContentSaveDB.SaveContentVersionProperty(IContent content)
   at EPiServer.DataAccess.ContentSaveDB.CreateAndSave(IContent content, Boolean delayPublish, Boolean forceCurrentVersion, Boolean forceNewVersion, String currentUser)
   at EPiServer.DataAccess.ContentSaveDB.<>c__DisplayClass16.b__15()
   at EPiServer.Data.Providers.SqlDatabaseHandler.<>c__DisplayClass4.b__3()
   at EPiServer.Data.Providers.SqlDatabaseHandler.<>c__DisplayClass7`1.b__6()
   at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
   at EPiServer.Data.Providers.SqlDatabaseHandler.ExecuteTransaction[TResult](Func`1 action)
   at EPiServer.Data.Providers.SqlDatabaseHandler.ExecuteTransaction(Action action)
   at EPiServer.DataAccess.ContentSaveDB.SaveInternal(IContent content, SaveAction action, Nullable`1 delayPublishUntil, String currentUser)
   at EPiServer.DataAccess.ContentSaveDB.Save(IContent content, SaveAction action, String currentUser)
   at EPiServer.DataAbstraction.ContentStore.Save(IContent content, SaveAction action, String currentUser)
   at EPiServer.DefaultContentProvider.Save(IContent content, SaveAction action)
   at EPiServer.Core.DefaultContentRepository.Save(IContent content, SaveAction action, AccessLevel access)
   at EPiServer.IContentRepositoryExtension.Save(IContentRepository repository, IContent content, SaveAction action)
   at EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.CreateContent(ContentReference parentLink, Int32 contentTypeId, Nullable`1 resourceFolderId, Boolean createAsLocalAsset, String name, IDictionary`2 properties, SaveAction saveAction)
   at EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.Create(ContentReference parentLink, Int32 contentTypeId, Nullable`1 resourceFolderId, Boolean createAsLocalAsset, String name, IDictionary`2 properties, Boolean autoPublish)
   at EPiServer.Cms.Shell.UI.Rest.ContentDataStore.Post(PostContentModel entity)
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at EPiServer.Shell.Services.Rest.RestControllerBase.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at EPiServer.Shell.Services.Rest.RestHttpHandler.ProcessRequest(HttpContextBase httpContext)
   at EPiServer.Shell.Services.Rest.RestHttpHandler.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
#134532
Sep 15, 2015 17:15
Vote:
 

Anyone solved this issue. I have the same ting but that is when we import /transfer data from one instance to an other instance of EpiServer. It seems like bug?!

2015-11-09 10:47:34,422 [817] ERROR EPiServer.Core.Transfer.TransferLogger: 10.5.3 Export/import error: Exception: Invalid use of read-only object, call CreateWritableClone() to create a writable clone.
System.NotSupportedException: Invalid use of read-only object, call CreateWritableClone() to create a writable clone.
at EPiServer.Data.Validator.ValidateNotReadOnly(IReadOnly readOnly)
at EPiServer.DataAbstraction.ContentType.set_Name(String value)
at SCommerce.Hay.Core.Models.Containers.ProductConfigurator.ProductConfigurationRootContainerModel.SetDefaultValues(ContentType contentType) in d:\BuildAgent\work\9788132fe6f896ff\Src\SCommerce.Hay.Core\Models\Containers\ProductConfigurator\ProductConfigurationRootContainerModel.cs:line 33
at EPiServer.Construction.ContentDataBuilder.ActionRecursively(IContentData contentData, ContentType contentType, Action`2 action)
at EPiServer.Construction.ContentDataBuilder.AddProperties(IContentData contentData, BuildingContext buildingContext)
at EPiServer.Construction.ContentFactory.CreateContent(ContentType contentType, BuildingContext buildingContext)
at EPiServer.Commerce.Catalog.Provider.Construction.CatalogContentFactory.CreateContent(ContentType contentType, BuildingContext buildingContext)
at EPiServer.Core.DefaultContentRepository.GetDefault[T](ContentReference parentLink, Int32 contentTypeID, CultureInfo language)
at EPiServer.Core.Transfer.ContentTransfer.CreateDefaultContent(Dictionary`2 propertyStringLookup, ContentReference parentLink, Boolean& isUsingPrototype)
at EPiServer.Core.Transfer.ContentTransfer.HasContentChanged(Dictionary`2 propertyStringLookup, ContentReference parentLink, IContent& content, Boolean& newContent)
at EPiServer.Core.Transfer.ContentTransfer.Import(RawContent rawContent, AccessLevel requiredDestinationAccess, Guid& importedPageGuid)
at EPiServer.Core.Transfer.ContentTransfer.Import(ITransferContentData content, AccessLevel requiredDestinationAccess)
at EPiServer.Enterprise.DataImporter.ImportContents[T](XmlTextReader reader, ZipPackage package)
at EPiServer.Enterprise.DataImporter.ImportStream(ZipPackage package, XmlTextReader reader, String partName)
at EPiServer.Enterprise.DataImporter.ImportRaw(ZipPackage package)
at EPiServer.Enterprise.DataImporter.Import()

#141065
Nov 09, 2015 12:06
Vote:
 

Hej  Peter Neuss  could you write your code snippet here, where you use SetDefaultValues(contentType) ? how do you populate default value.?  

#141068
Edited, Nov 09, 2015 12:28
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.