473,799 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serialization and default construction

My default constructors do not seem to be being called when
deserializing using .NET.

Consequently some of my objects that are marked [NonSerialized] are not
in a initialised state?

Whats going on here? Should not the default constructors be called?

Mar 6 '06 #1
2 886
Well it seems i may have solved this myself.

Your class has to implement the ISerializable interface.

And then a default constructor will be called

HerbyClass(Seri alizationInfo^ info, StreamingContex t context)

This will then implicitly call the default constructors on any private
objects that are attributed with
[NonSerialized]

This was not obvious and definately requires a more advanced
understanding.
I would like someone to confirm this is correct?

Mar 6 '06 #2
Im also having problems now with above, my member classes do not seem
to be being (de)/serialized correctly
e.g.

virtual void GetObjectData(S erializationInf o^ info, StreamingContex t
context){

info->AddValue("_si" , SchemeInputs);
}

Where SchemeInputs are instances of my own class previously auto
serialized.
HerbyClass(Seri alizationInfo^ info, StreamingContex t context){

ResultArray temp;

SchemeInputs = safe_cast<Resul tArray^>(info->GetValue("_si" ,
temp.GetType()) );
}
Anbody know what is wrong with above?

If class B inherits from A and has class C as a member and i implement
ISerializable for class B, does this mean i have to also implement
ISerializable for class A and C ???

Again i have found away around the problem, i have removed
ISerializable and implemented IDeserializatio nCallback

I have changed my private [NonSerialized] members from
HerbyClass m_c;
To
HerbyClass^ m_c;

and then dynamically create them on the invocation of

virtual void OnDeserializati on(Object^ sender)
This is not that intuitive, im not convinced its correct ????

Mar 6 '06 #3

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

Similar topics

10
2408
by: Ook | last post by:
I'm having trouble comprehending what exactly "default construction" is. I know how to provide a constructor with initial values, so that if I, for example, in my code do this: MyClass zoot(1,2); It would instantiate MyClass, passing 1 and 2 to my constructor which in turn would do whatever I want it to. Would a default constructor be as follows:
3
3179
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. It seems that either I can use default serialization or implement ISerializable. Is there any way to do both (e.g. extend the default serialization). In other words, I want to be able to implement my custom serialization code but call the...
10
1409
by: Jesper | last post by:
Hi, I'm writing a program which is, and will continue to be, constantly extended with functionality that require information. Until now the source of this information has been found and modified using notepad in a txt file that was parsed into fields in objects. (This solution because this was the format that an older fortran program was using and we needed to do it in this way in a transition period). Now I would like be able to save...
2
1084
by: Carlo, MCP | last post by:
Hello, I'm troubling from months with a serious serialization problem that I'm not able to solve. I try to describe as simply as I can. 1) I have a class tha does something with colors. All default values are obviously NOT serializad. Instead, they are serialized when they are different from those of default. Sample: Class ColorClass Private mBackground=Color.White Public Property Background
15
2414
by: Jacques | last post by:
Hi I am an dotNet newby, so pardon my ignorance. I am looking for a method of saving/copying a managed class to a stream/file WITHOUT saving the object's state, eg. if I have a ref class with two int32's as its data members, the binary file of that class must have a size of 8 bytes (i.e. only contains class data members, not methods etc.). Is serialization the answer to the above problem? If I understand correctly, the reason that...
3
2643
by: Zachary Turner | last post by:
Hello, I have a situation where I would like to perform custom serialization and deserialization of an existing .NET framework object (specifically, System.DateTime). Is there a common paradigm here, for how I can override the default behavior of DateTime serialization and provide my own? I want to use this custom serialized DateTime in many places, and don't want to provide custom serialization routines for every single object that...
43
3841
by: JohnQ | last post by:
Are a default constructor, destructor, copy constructor and assignment operator generated by the compiler for a struct if they are not explicitely defined? I think the answer is yes, because "there is no difference between a struct and a class except the public/private access specification" (and a few minor other things). When I create a class, I always start by declaring the default constructor, copy constructor and assignment operator...
2
3848
by: Peter Duniho | last post by:
I've been learning about mechanisms .NET offers to export data. The initial goal is to see what sorts of ways are available to save an application's state (document, internal database, whatever). Not counting storing data in a database (which is obviously suitable for some things, but not necessary or even necessarily desirable for other things), here's what I've explored: Serializable attribute, with BinaryFormatter and SoapFormatter...
0
4714
by: JosAH | last post by:
Introduction Upon hearing the word, "Serialization", the first question which comes to mind is ... "What is Serialization?" We know that we can create resusable objects in Java. But the lifetime of those objects lasts only as long as the Java virtual machine is running. Once we close the JVM, we lose all those objects. What if someone wants objects to be available after JVM restarts? This is where Serialization comes into play. ...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2941
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.