Could you elaborate a bit on what the actual problem is? Do you have code in your application that depends on SocialImages actually being a DynamicList of ImageItems while it's null from time to time. Or is the null value resulting in an exception in the EPiServer framework?
Hi, let me rephrase the problem:
1. We have a page StartPage, and it has a custom property SocialImages, that is actually a list of custom objects.
2. We are trying to get property of this page as (examples):
2.1 ServiceLocator.Current.GetInstance<IContentLoader>().Get<StartPage>(PageReference.StartPage).SocialImages
2.2 From ContentArea, somePage.Contents.OfType<StartPage>().First().SocialImages
Both options sometimes return null. If we will publish the StartPage, both variants will return the correct saved object. It can be reproduced as on the development servers (+QA) as on a staging one.
Please let me know if you need some more details.
UPDATE 1:
As far as i remember the issue was related with the language. We are using the following globalization string:
<globalization culture="is-IS" uiCulture="en"
We have to use the "en" uiCulture because the EpiServer Admin doesn't have the translation to Icelandic language.
If i'm right if we try to get the page using the specific language branch, it works ok.
I am also facing the same problem. To fix this, please follow the small workaround.
The main problem is custom property not able to get the latest published value from the current page reference. So you need to explicitly get the latest version of the page, please find the reference code below and hope that will help you.
private PageData GetLatestSelectedPageVersion(string id)
{
PageData page = DataFactory.Instance.GetPage(new PageReference(int.Parse(id), true));
PageVersionCollection pageVersions = PageVersion.List(page.PageLink);
return DataFactory.Instance.GetPage(pageVersions.Last().ID);
}
or
public static PageData GetLastVersion(PageReference pageRef)
{
PageVersionCollection pageVersions = PageVersion.List(pageRef);
return DataFactory.Instance.GetPage(pageVersions.Last().ID);
}
Fetching the version list and fetching a specific version from DataFactory is bad from a performance perspective since versions are not stored in the cache which means that this call will always result in a database call.
I'm assuming that you have a custom property where you convert a backing value, like xml in a string, to a dynamic list. Have you debugged this property when you get the problem to see what the underlying value is?
Thanks! I really didn't want to load the page twice from the database, but if it is the only option, I'll try.
It is NULL before we are trying to convert something to a List!
Aliaksei: I suggest that you open a support case if you believe that you are experiencing a bug in the EPiServer framework. Another option would be to upgrade to EPiServer 7.5 to see if you still encounter the same issue there.
Thank you. It works as supposed.
We have two identical production servers (episerver hosting) in cluster. On the first the issue is reproducible, on the second one not. What do you think?
I actually have no idea so I suggest that you open a support case if this still is an issue.
I can confirm that I am having the same issue with our custom property. The workaround with loading the latest version works, but as it is bad for performance we really would like another approach. Did you file a support ticket?
I am using patch 4.
It seems related to a block being internal VS shared. When I add the block with the custom property as an internal property on the page, it will be empty when populated on application restart and builds. But if it is a shared block added to a content area the property will have the correct value. Seems related to cache. Any thoughts?
This issue seems to be related to when EPiServer initially cache the pages at application start. I've tried now to empty the cache in the controller (thus rebuilding it) and then the properties will appear correctly on the next request. Probably therefore they show up in edit mode and also works after a publish of the page... How can I work around this???
When a page (or other content instance) is loaded an instance of corresponding backing property data should be created for each property.
If you turn on log4net debugging for namespace EPiServer.Construction do you get any messages around failures of creating types?
I tried turning on Construction and Initialization but no errors are logged. But if it was something wrong with the backing type, why would it work when in edit-mode or when fetching the latest version of a page?
At the moment I am using the custom fetcher for the pages that are having issues, but it kinda sucks to have to do it like this:
public static T GetPageOverrideCache<T>(PageData pageData) where T : PageData
{
var page = (T) pageData;
var ctx = ServiceLocator.Current.GetInstance<IContentLoader>();
var ctxVersions = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
var versions = ctxVersions.List(page.PageLink, page.LanguageBranch).Where(v => v.Status == VersionStatus.Published).ToList();
if (!versions.Any())
versions = ctxVersions.List(page.PageLink, page.LanguageBranch).ToList();
return ctx.Get<T>(versions.Last().ContentLink);
}
Dear Colleagues,
We have faced the issue with custom properties. For example we have the following definition on a page:
[BackingType(typeof(ImageItemProperty))]
[CultureSpecific]
public virtual DynamicList<ImageItem> SocialImages { get; set; }
The problem is that sometimes when we trying to retrieve the page programmatically, we have "nullable" custom properties.
If we will republish page (edit some property and publish again) - everything works good until the next application pool recycle (after the deployment).
We have verified the code with the real code samples — everything is correct. I do not know where to look next. Looks like it works ok after the page publish when all properties are correctly added to the system cache.
This is an urgency issue and i hope that someone will help us.
Thanks in advance.