471,353 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,353 software developers and data experts.

Deserialization Issue

I have a class that inherits from CollectionBase. My derived class raises
events whenever items are added or removed from the collection. When I try
to serialize my class I get errors because of any classes that are listening
for the events that are raised. And since it seems that the <NonSerialized>
attribute does not work for events in VB.NET I had to implement the
ISerializable interface.

I am able to serialize with no problems within the GetObjectData method. My
problem is in the protected constructor used when trying to deserialize the
class. I am trying to use the GetValue method but am getting a
TargetInvocation exception. I think it is because I am trying to use a
generic Object type when calling the method. I need to do this because I
have no idea beforehand what type of object was in the ArrayList when it was
serialized.

Assuming that (in order) a String, Int32, and Single where written to the
stream during serialization, the following code does not work.

Dim obj As Object
List.Add(info.GetValue("Item0", obj.GetType))
List.Add(info.GetValue("Item1", obj.GetType))
List.Add(info.GetValue("Item2", obj.GetType))

But this code does:

List.Add(info.GetString("Item0"))
List.Add(info.GetInt32("Item1"))
List.Add(info.GetSingle("Item2"))

How can I retrieve the collection of items that was in the ArrayList if I do
not know the TYPE of object it was when it was written.

- Jason
Jul 21 '05 #1
0 797

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Mike Sarbu | last post: by
3 posts views Thread by Amadelle | last post: by
3 posts views Thread by parrot toes | last post: by
5 posts views Thread by frustratedWithDotNet | last post: by
12 posts views Thread by yoshijg | last post: by
reply views Thread by anand sancheti | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.