Creating new content in events triggered by import process might cause errors

Found in

EPiServer.CMS.Core 7.5.394.2

Fixed in

EPiServer.CMS.Core 11.1.0


Jun 29, 2017


Nov 21, 2017


CMS Core


Closed, Fixed and tested


If a new content item is created with ImportContext, e.g.' by attaching an event handler to IDataImportEvents.ContentImported and then, in the event handler, something like this happens

var page = contentRepository.GetDefault<ContentFolder>(ContentReference.RootPage);
page.Name = "something";

an exception is thrown PropertyDate is out of range. Example: [Importing content 6202_8055] Exception: You must enter a value between 01/01/1753 and 12/31/9999 for "EPiServer.Core.PropertyDate".

Note: This is because the DataImporter sets a context key ContextCache.Current[UseIChangeTrackingSavedKey]. When that is set, it does not set the saved date to DateTime.Now but instead uses the date from the content itself. This is so the content gets the same time at it has in import package. While this works for content in the package, if other content is created (e.g., from an event handler), it will fail. We should use DateTime.Now for those content items instead of throwing an exception.