ObservableObject is not marked as serializable?

Nov 21, 2012 at 11:13 AM

Hi,

I tried to use the ObservableObject (WPF4, 4.1.24.16313) for a small model, which has to be serialized. But I got a Runtime.Serialization.SerializationException:

The german message is:

Der Typ "GalaSoft.MvvmLight.ObservableObject" in Assembly "GalaSoft.MvvmLight.WPF4, Version=4.1.24.16313, Culture=neutral, PublicKeyToken=63eb5c012e0b3c1c" ist nicht als serialisierbar gekennzeichnet.

Which means: The typ ObservableObject ... is not marked as serializable.

If I follow the MIX 11 video and thought that ObservableObject should be serializable. First the "Friend class" should be small and serializable and at about 10:00 min it inherits from ObservableObject.

See also: http://mvvmlight.codeplex.com/discussions/349115

lbugnion, May 21 at 8:54 AM

The choice to work with INPC on the Model is driven by simplicity. Using a DO there is overkill because DOs are quite heavy and "drag" with them a lot of features that only make sense on a UI. For instance, DOs are not serializable while INPC implementations are, of course.

In MVVM Light V4, you can use the ObservableObject class and derive from this.

Is this a misunderstanding or a bug?

Best regards,

Mike

 

Coordinator
Nov 21, 2012 at 12:29 PM

Hi,

The concept of being serializable is an interesting issue. In my presentation, the object is serialized using a serializer I wrote, which does not require specific attributes. However the built in serializers in .NET choke when the base classes are not marked as serializable. Honestly I never understood Microsoft’s need for that. It would be much better to assume that classes are serializable, unless marked otherwise. If you use other widespread serializers such as JSON.NET for instance, the policy there is to serialize everything public, unless it is marked as “not serializable”.

Unfortunately, the built in serializers do not do that, and so the burden is on every framework maker to add the series of attributes needed to palliate that shortcoming.

Right now, ObservableObject does not carry these attributes. Mostly, people who work in applications using MVVM Light did not feel that need, because we typically don’t use the built in serializers. They are slow and not very friendly. I see two possibilities in your scenario:

- Either use a modern serializer such as JSON.NET or

- Build your own ObservableObject, which is really quite easy. In fact you can find and modify the code on the MVVM Light site on Codeplex.

I might eventually mark ObservableObject as serializable, but I am not sure I will. Once I add this attribute, then I will get requests for others and I am not sure I want to promote the usage of the inferior serializers that are built into .NET.

Hopefully this helps a bit

Laurent

From: mike969 [email removed]
Sent: Wednesday, 21 November, 2012 13:13
To: laurent@galasoft.ch
Subject: ObservableObject is not marked as serializable? [mvvmlight:404080]

From: mike969

Hi,

I tried to use the ObservableObject (WPF4, 4.1.24.16313) for a small model, which has to be serialized. But I got a Runtime.Serialization.SerializationException:

The german message is:

Der Typ "GalaSoft.MvvmLight.ObservableObject" in Assembly "GalaSoft.MvvmLight.WPF4, Version=4.1.24.16313, Culture=neutral, PublicKeyToken=63eb5c012e0b3c1c" ist nicht als serialisierbar gekennzeichnet.

Which means: The typ ObservableObject ... is not marked as serializable.

If I follow the MIX 11 video and thought that ObservableObject should be serializable. First the "Friend class" should be small and serializable and at about 10:00 min it inherits from ObservableObject.

See also: http://mvvmlight.codeplex.com/discussions/349115

lbugnion, May 21 at 8:54 AM

The choice to work with INPC on the Model is driven by simplicity. Using a DO there is overkill because DOs are quite heavy and "drag" with them a lot of features that only make sense on a UI. For instance, DOs are not serializable while INPC implementations are, of course.

In MVVM Light V4, you can use the ObservableObject class and derive from this.

Is this a misunderstanding or a bug?

Best regards,

Mike

Nov 21, 2012 at 1:47 PM

Hello Laurent,

thank you for your fast response (and - of course - for the mvvm light toolkit).

Ok, now its clear. So writing my own ObservableObject shouldn't be to hard.

The info about the built in serializers is interesting. I have to save large datafiles with a lot of different object types (sometimes > 50MB). I use the built in BinaryFormatter. Getting a fast serializer which makes smaller files would be nice.

 

Best regards,

Mike

Coordinator
Nov 21, 2012 at 2:04 PM
For speed, I like JSON.NET’s binary serializer. It creates BSON (binary JSON) and is really fast. It’s be interesting to time it against the one you are using.
Cheers
Laurent
Sent from Windows Mail
From: mike969
Sent: ‎November‎ ‎21‎, ‎2012 ‎15‎:‎47
To: laurent@galasoft.ch
Subject: Re: ObservableObject is not marked as serializable? [mvvmlight:404080]

From: mike969

Hello Laurent,

thank you for your fast response (and - of course - for the mvvm light toolkit).

Ok, now its clear. So writing my own ObservableObject shouldn't be to hard.

The info about the built in serializers is interesting. I have to save large datafiles with a lot of different object types (sometimes > 50MB). I use the built in BinaryFormatter. Getting a fast serializer which makes smaller files would be nice.

Best regards,

Mike