We just encountered a curious incident in our production environment.
A page property was not reflected to our page class that inherited from PageData, the reason was that it was missing the virtual modifier.
Normally we would get a YSOD like this:
The property 'Hide' on the content type 'SettingsBlock' is autogenerated but not virtual declared.
However, our page class inherits the property from an interface and is thereby always virtual.
Looking at EPiServer.DataAbstraction.RuntimeModel.ContentDataAttributeScanningAssigner.AssignValuesToPropertyDefinition (our version is 9.6.0) the logic is to verify that the property is virtual and public.
A fix could be to also test if the property is not final.
I created the following code to show the test case:
void Main()
{
typeof(B).GetProperty("P1").GetGetMethod().IsVirtual.Dump(); // true
typeof(B).GetProperty("P1").GetGetMethod().IsFinal.Dump(); // false
typeof(B).GetProperty("P2").GetGetMethod().IsVirtual.Dump(); // true
typeof(B).GetProperty("P2").GetGetMethod().IsFinal.Dump(); // true
}
class B : A
{
public virtual bool P1 { get; set; }
public bool P2 { get; set; }
}
interface A
{
bool P1 { get; set; }
bool P2 { get; set; }
}
Hi there,
We just encountered a curious incident in our production environment.
A page property was not reflected to our page class that inherited from PageData, the reason was that it was missing the virtual modifier.
Normally we would get a YSOD like this:
The property 'Hide' on the content type 'SettingsBlock' is autogenerated but not virtual declared.
However, our page class inherits the property from an interface and is thereby always virtual.
Looking at EPiServer.DataAbstraction.RuntimeModel.ContentDataAttributeScanningAssigner.AssignValuesToPropertyDefinition (our version is 9.6.0) the logic is to verify that the property is virtual and public.
A fix could be to also test if the property is not final.
I created the following code to show the test case: