CodeDom Serialization Problem

C

coderGuy

I have a problem with serializing user controls to
persistant collections with the Code Dom. I have followed
many of the examples I have found, and the serialization
works except for one problem.

I am using the attribute -
DesignerSerialization.Visibility.Content...

Somehow I am losing the "association" between the
instance of the collection I am serializing, and when the
control is reloaded (or when you run the application).
While you remain in normal design-time mode, everything
is serialized properly straight to the code-behind.
Everything is also removed properly straight from the
code-behind (when removing an object)... I have
implemented TypeDescriptors / Convertors / Designers /
etc...
But I still have this problem.

After I reload or run the app. - then what happens is it
becomes disconnected with the serialized collection. It
doesn't know that there was a previous instance of it
that needs to be de-serialized, instead the collection
acts like a new "blank" collection on each reload.


For instance...

Let's say you have a Parent/Container Control that holds
all your child controls inside it. Now you have a
custom-collection (inherits from collectionBase) that
holds the references of the child controls. The custom
collection is of course exposed as a property of the
parent control, standard OO design...

You drop the Parent/Container control on a form. Now you
add child controls to the Form. Well so far - so good.
The code is generated properly in the code-behind as such:
ParentControl.ChildControlCollection.Add(SomeChild)...
etc...

However, you reload the project or run the application.

The CODE is still in the code-behind, but the objects are
no longer physically appearing in the control, even
though the objects are still in the code behind.

Also, when you try to remove an object from the
collection, the object does not exist inside the
collection anymore, instead it only exists in the CODE
editor.

Somehow the collection is being re-instanced or
disassociated with the collection that has been
serialized.

Does anyone have any specifics or information about
where, when, and how the De-Serialization is taking place
during the automated
DesignerSerialization.Visibility.Content process?

I have gone over my code so many times looking for some
place I might have "over-wrote" the instance of the
collection. But it just isn't there, I just don't see why
the instance of my collection would be disassociated when
I run the program or re-load VS.NET...


Thanks for any info, (Really stuck here)

CoderGuy
 
G

Guest

I worked out a lot with serializing object members that
represent collection of other objects and I concluded
that the way it is done automatically is not good.
Therefore whenever I need to persist collections I always
write my own codeSerializer...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top