Try our conversational search powered by Generative AI!

PTB2 page type property InvalidCastException


I use Page Type Builder 2 to define my page types. On one page type I have defined a property like so:

[PageTypeProperty(Type = typeof(PropertyWeekDay))]
public virtual PropertyWeekDay Weekdays { get; set; }

If I access it from my page template, I get an InvalidCastException with the message 

Unable to cast object of type 'System.Int32' to type 'EPiServer.SpecializedProperties.PropertyWeekDay'.

I thought this would be handled automatically by PTB, but I guess not... 

What do I need to do and where, if I want to use the property as a strongly typed PropertyWeekDay and not an int? What's the recommended approach?


Jun 04, 2012 9:31

PTB returns the value of the property, not the property itself, and if the value is an int, you have to return an int, or something that is castable with an int.

If you want the property and not the value, just create a WeekdaysProperty that returns this.Property["Weekdays"] as PropertyWeekDay;

Jun 04, 2012 10:17
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.