Skip to main content

Back-End Development

Bug Fixing: Lazy loaded property value is not supported by the current property instance

computer warning laptop

While upgrading from CMS v11 to v12, we ran into an error that read “Lazy loaded property value is not supported by the current property instance”. Unfortunately, the stack trace didn’t really say what the problem was. Here is that stack trace:

System.InvalidOperationException: Lazy loaded property value is not supported by the current property instance
   at EPiServer.DataAccess.Internal.LazyPropertyValueLoader.SetValue(PropertyData property, PropertyDataRecord dataRecord, Func`3 valueConverter)
   at EPiServer.DataAccess.Internal.ContentDB.ReadPropertyData(PropertyData prop, DbDataReader reader, ContentReference contentLink, CultureInfo language)
   at EPiServer.DataAccess.Internal.ContentListDB.ReadCustomProperties(DbDataReader reader, Dictionary`2 allFetchedItems, Boolean isReadingVersions)
   at EPiServer.DataAccess.Internal.ContentListDB.ReadPublishedList(DbCommand cmd)
   at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass26_0`1.<Execute>b__0()
   at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
   at EPiServer.DataAccess.Internal.ContentListDB.LoadSpecificContentInstances(IList`1 contentLinks, Int32 languageBranchID)
   at EPiServer.Core.Internal.DefaultContentProvider.BatchLoad(IList`1 contentLinks, Func`2 dbLoader)
   at EPiServer.Core.Internal.DefaultContentProvider.LoadContents(IList`1 contentReferences, ILanguageSelector selector)
   at EPiServer.Core.ContentProvider.GetContentBatch(IList`1 batch, ILanguageSelector selector, List`1& contents, Dictionary`2& contentMap)
   at EPiServer.Core.ContentProvider.GetScatteredContents(IEnumerable`1 contentLinks, ILanguageSelector selector)
   at EPiServer.Core.Internal.ProviderPipelineImplementation.GetItems(ContentProvider provider, IList`1 contentLinks, LoaderOptions loaderOptions)
   at EPiServer.Core.Internal.DefaultContentLoader.GetChildren[T](ContentReference contentLink, LoaderOptions loaderOptions, Int32 startIndex, Int32 maxRows)
   at EPiServer.Core.Internal.DefaultContentLoader.GetChildren[T](ContentReference contentLink, LoaderOptions loaderOptions)
   at MyProject.Business.Settings.SettingsService.UpdateSettings() in C:\sourcecode\MyProject.cms\src\MyProject.Business\Services\SettingsService.cs:line 185
   at MyProject.Business.Settings.SettingsService.RegisterContentRoots() in C:\sourcecode\MyProject.cms\src\MyProject.Business\Services\SettingsService.cs:line 208
   at MyProject.Business.Settings.SettingsService.InitializeSettings() in C:\sourcecode\MyProject.cms\src\MyProject.Business\Services\SettingsService.cs:line 142
   at MyProject.Web.Middleware.Initialization.ApplicationBuilderExtensions.InitializeSettings(IApplicationBuilder app) in C:\sourcecode\MyProject.cms\src\MyProject.Web\Middleware\Initialization\ApplicationBuilderExtensions.cs:line 105
   at MyProject.Web.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\sourcecode\MyProject.cms\src\MyProject.Web\Startup.cs:line 146
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
   at EPiServer.Forms.Samples.FormsSamplePublicStaticFileStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at EPiServer.Forms.FormsPublicStaticFileStartupFilter.<>c__DisplayClass1_0.<Configure>b__0(IApplicationBuilder app)
   at EPiServer.GoogleAnalytics.GoogleAnalyticsStaticFileStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.<StartAsync>d__37.MoveNext()

Fixing the Problem

Optimizely CMS – the Importance of GUIDs and Assembly Names

A colleague found that when upgrading from v11 to v12, PropertyLists were crashing with little to no error messages. The solution was to convert all instances of [PropertyDefinitionTypePlugIn] to include a GUID parameter before converting the database. Making this change and then loading the v11 site will update the database with the new GUID.

Checking the Database

I thought that’s what I had done, but I still had this error, so I checked the debug console and found a line that read:

"Unable to create a PropertyData instance of Type: 'MyProject.Data.Models.PoC.KeyValueItemProperty' Assembly: 'MyProject.Data'. Will fallback using the data type instead."

That KeyValueItemProperty was one of the PropertyLists to which we added a GUID, so I looked in the database.

SELECT *
FROM [MyDatabase].[dbo].[tblPropertyDefinitionType]
WHERE Name like '%KeyValueItemProperty%'

Sure enough, there were now two rows for KeyValueItemProperty in that table. One of them had the GUID and the older one did not.

pkID    Property    Name    GUID    TypeName    AssemblyName    fkContentTypeGUID   DisplayName GroupName   Hidden
1000    13  KeyValueItemProperty    NULL    MyProject.Data.Models.Properties.KeyValueItemProperty   MyProject.Data  NULL    NULL    NULL    0
1223    13  KeyValueItemProperty    E05C9EF6-E538-489E-AAF4-206EB431E41B    MyProject.Data.Models.Properties.KeyValueItemProperty   MyProject.Data  NULL    NULL    NULL    0

I ran a quick UPDATE command to add the GUID to the older row, presumably the one with associated content, like this:

UPDATE [MyDatabase].[dbo].[tblPropertyDefinitionType]
SET [GUID] = (SELECT [GUID] FROM [MyDatabase].[dbo].[tblPropertyDefinitionType] WHERE pkID = 1223)
WHERE pkID = 1000

To keep the database clean, I removed the duplicate row:

DELETE 
FROM [MyDatabase].[dbo].[tblPropertyDefinitionType]
WHERE pkID = 1223

I tried launching the site, and another PropertyList threw an error like KeyValueItemProperty. I repeated the same SQL queries to update the database with the GUID. Once I did that, the site launched cleanly.

To be sure that I had corrected all duplicate rows, I ran the following query and found a few more PropertyLists. These apparently didn’t have content associated with them, yet, so they didn’t throw an error.

SELECT * 
FROM [MyDatabase].[dbo].[tblPropertyDefinitionType] 
WHERE Name IN ( 
    SELECT Name 
    FROM [MyDatabase].[dbo].[tblPropertyDefinitionType] 
    GROUP BY Name 
    HAVING COUNT(Name) > 1)

I ran the same SQL queries to clean those up, and now I have a working site. Visual Studio no longer throws errors about a lazy loaded property value not being supported.

Note: We’re running EPiServer.CMS version 12.27.1.

Please share your insight into my solution to this problem–whether it works or doesn’t, or if there’s something I missed. The previous forum posts regarding this error were from pre-2018 and recommended adding a setting to web.config. I found one post that said adding that setting didn’t resolve the issue anymore.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Nick Hamlin, Lead Technical Consultant

Nick Hamlin is a Lead Technical Consultant with Perficient. He has been programming for over 20 years, focusing on Optimizely CMS and Commerce since 2018. In his free time, he enjoys playing bar trivia, writing music, cooking, and finding cheap airfare to travel the world. Nick is fluent in English & Spanish and has studied French, Portuguese, and German.

More from this Author

Follow Us