473,473 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Serialization of non-Serialized collection

I have collection based class wich is non serializable (for some reason)
[NonSerClass]
I want to create another class with similar to [NonSerClass], but
serializable [SerClass]
so doing:

public class NonSerClass:CollectionBase
{Whatever}

[Serializable]
public class SerClass : NonSerClass

This working fine, except the little problem. while casting from NonSerClass
to SerClass I recieve "Invalid Cast" exception, as well as attempts like
NonSerClass no_ser_foo = new NonSerClass();
SerClass ser_foo =no_ser_foo as SerClass;
returns null

Please advice. Why is it

TNX

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
Nov 16 '05 #1
1 1193
Tamir,

The reason that this doesn't work is that you can not cast a reference
up when the type is not that of the derived type. no_ser_foo is just a
reference to an instance of NonSerClass. If you want an instance of
SerClass, you have to create it yourself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:On**************@TK2MSFTNGP10.phx.gbl...
I have collection based class wich is non serializable (for some reason)
[NonSerClass]
I want to create another class with similar to [NonSerClass], but
serializable [SerClass]
so doing:

public class NonSerClass:CollectionBase
{Whatever}

[Serializable]
public class SerClass : NonSerClass

This working fine, except the little problem. while casting from
NonSerClass to SerClass I recieve "Invalid Cast" exception, as well as
attempts like
NonSerClass no_ser_foo = new NonSerClass();
SerClass ser_foo =no_ser_foo as SerClass;
returns null

Please advice. Why is it

TNX

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bjorn | last post by:
I know you should be careful before blaming internal frameworks, but this definitely does look like an internal bug. When serializing a ChildClass that inherits a BaseClass containing a struct...
0
by: Donovan Zimmerman | last post by:
I'm getting the above error in 1 solution/project for the following code but the exact same code works fine in other projects. References are the same. I also get xml serialization error from a web...
4
by: Aaron Clamage | last post by:
Hi, Could someone please confirm the following? I think I have found a subtle .NET serialization bug. It occurs when object has a list of items containing another object of the same type and...
2
by: Maximus | last post by:
Hi Everyone, I was using Inprocess session objects, but incase of aspnet process crashes the session objects were lost as a result I decided to shift to out of porocess session objects. For this...
2
by: jakk | last post by:
Below is the exception that Iam getting. It says that the DataView that Iam storing in the session is not Serializable. BUt works fine if I store in the inproc session and fails if I switch to...
0
by: Abhishek Padmanabh | last post by:
I have been trying out boost's serialization library for the past few days. And I have come across a problem serializing a class that has a reference member. The code is posted as below: ...
11
by: William | last post by:
I'm looking for an example that would show how to serialize a c++ object at it's simplest w/o using any other api's. I have a class that I want to serialize and then pass to my obj-c class so I can...
5
by: RobinS | last post by:
I want to serialize a class that I am using to retain some information the user types into a screen. I have 3 questions. 1) I serialized it as XML to start with. This works, but how do I...
4
by: camarkco | last post by:
Why does C# go out of it's way to prevent this? Mark
7
by: Michael | last post by:
Hello everybody, I have a console app which runs some queries on a database and writes the results into an excel file. I'd like to build a GUI which would allow to give some parameters to the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.