NHibernate PropertyAccessException Invalid Cast, specified cast is not valid

If you receive this error then you have probably mixed up some data types between your class (class.cs) file and your mapping (class.hbm.xlm) file.

For example you have a property defined in your class file as a string and then in your mapping file as an int. To repair the PropertyAccessException Invalid Cast (check your mapping for property type mismatches); setter of NAMESPACE.CLASSNAME as shown in the following image, simply verify you have the same data type within your class file as you do in your mapping file.

image

The inner execution is:

  • {“Die angegebene Umwandlung ist ungültig.”}
  • {“The specified cast is not valid.”}