Try our conversational search powered by Generative AI!

InvalidCastException when accessing a property



I get an InvalidCastException when trying to access a property. We have recently upgraded from EPiServer 6 to 7.5, and I suspect this is the cause.

It says it can't cast from string to xhtml string, which I know it can't do, but the problem is where it occurs.

This is the problem line: if(articlePage.MainIntro != null)

So, I set a breakpoint, and tried running articlePage.MainIntro in the Immediate Window, and it threw the exception simply by accessing the property.

Could there be some sort of mismatch between the property type and what is saved in the database?

Aug 01, 2014 14:16

That sounds like a reasonable cause.

You could go to admin mode and check if that is the cause. Select content type tab find the content type that causes the problem and then click on MainIntro property, there you will se which type it has.

I am not sure if you can change the type of the property from the UI (certain values that comes from code is not editable in admin mode). If not you could temporary comment out the property in code, then go to admin mode and chage the type to the desired one (string => xhtmlstring). Then after saving the value you can add back the property to your model again.  

Aug 02, 2014 0:10

Switching the type of the property in admin worked great.

Thanks for the help!

Aug 04, 2014 13:23
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.