Catel and Entity Framework 5

Topics: Feature requests
Aug 24, 2012 at 10:11 AM

Hello again.

I upgraded my Project from Entity Framework Version 4 to 5.

In my Project I have a Model with a Catel Property (named Profile) with type that is generated from EF.

In EF 4 the class was decorated with the [Serializable] attribute. But not in EF 5.

So when I instance an object of the model, I get an exception: Property 'Profile' is not valid, not serializable.

The exception is catched in the ManagedViewModel class. In method OnViewModelCommandExecuted.

Maybe an idea how to solve this?

Aug 24, 2012 at 10:16 AM

The RegisterProperty has an overload that allows to specify whether a property is serializable or not.

Aug 24, 2012 at 11:46 AM
Edited Aug 24, 2012 at 11:46 AM

I registered in this way:

        public static readonly PropertyData ProfileProperty = 
RegisterProperty("Profile"typeof(Profile), null,null,false);

but get the same error :-(

Aug 24, 2012 at 11:49 AM

Maybe you should also decorate your class with the AllowNonSerializedMembers attribute. It's been a long time since I used that feature myself, so I have to dive deep into my brains for this :)

Aug 24, 2012 at 12:05 PM


I can't find this attribute anywhere!

Aug 24, 2012 at 12:06 PM

AllowNonSerializableMemberrs attribute docs.

Aug 24, 2012 at 12:13 PM

Also don't works. Samer error. :-(

Aug 24, 2012 at 12:21 PM

Now it works. Compiled again. Thanks.

Aug 24, 2012 at 12:35 PM

But a lot's of work to register all Propertys in an other way an decorate all classes with the AllowNonSerializableMembers attribute. :-(

Aug 24, 2012 at 1:10 PM

I agree. You can of course create your own ModelBase deriving from DataObjectBase with a RegisterPropertyAsNonSerializable which should save you a lot of work. If you are using Fody, I might introduce it as an option for the weaver.

Aug 24, 2012 at 1:44 PM
Edited Aug 24, 2012 at 1:46 PM

No Fody but Resharper.

Aug 24, 2012 at 1:50 PM

Yes. Catel.Resharper. See

If you want the feature there, let us know in the issue tracker, then we will implement it.

Aug 24, 2012 at 1:52 PM
Edited Aug 24, 2012 at 1:52 PM

Or why Fody. You can also do this with resharper. Do I understand something wrong?

Aug 24, 2012 at 1:53 PM

It's just a preference of code generation versus weaving. With Resharper, you still write the code (although it is automated). With fody, you can write public string FirstName and the compiler will turn it into a catel property.

Aug 24, 2012 at 1:58 PM
Edited Aug 24, 2012 at 2:52 PM

It could be a new option on CatelR#.

1) Add an option to generation dialog to register property as non serializable (default will be true)

2) Add a context action to convert a RegisterProperty to RegisterPropertyAsNonSerializable and support to convert RegisterPropertyAsNonSerializable into RegisterProperty (First we have to add RegisterPropertyAsNonSerializable)

Aug 24, 2012 at 5:37 PM

Catel will not provide a custom method RegisterProperytAsNonSerializable because it is already provided by the RegisterProperty method. It's just a different boolean value in RegisterProperty.

Aug 24, 2012 at 7:05 PM

Ok, it wil be only an option on generation dialog.

Aug 27, 2012 at 6:09 AM

Ok. Maybe it's also interesting to insert an option for fody. Before I don't know fody. At the moment I test it.

Aug 27, 2012 at 12:48 PM
Edited Aug 27, 2012 at 12:50 PM

If your are able to build it from the source you could try out the new options

Aug 7, 2013 at 7:08 AM
I want to use fody in my models but for properties like below how can i use fody?
public virtual InvoiceType InvoiceType
     get { return GetValue<InvoiceType>(InvoiceTypeProperty); }
     set { SetValue(InvoiceTypeProperty, value); }

public static readonly PropertyData InvoiceTypeProperty = RegisterProperty("InvoiceType", typeof(InvoiceType), null, null, false);
Aug 7, 2013 at 3:22 PM
Fody will not weave properties that are already catel properties. If you want customization of the PropertyData, then you will need the RegisterProperty.