473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

XmlSerializers, Structs, and Default Constructors

Hi, this is just out of curiosity really. I had a struct, requirements
changed and I needed to inherit from it, so I made it into a class.

After the change, XmlSerializer choked because XmlSerializable classes
require a default constructor. Why don't structs?

Jun 19 '06 #1
2 1192
structs are not objects, but rather a value types. they are allocated on the
stack, rather than the heap. to improve value type performance, they do not
have contructors like objects.

-- bruce (sqlwork.com)

"Flinky Wisty Pomm" <Pa********@gmail.com> wrote in message
news:11**********************@r2g2000cwb.googlegro ups.com...
Hi, this is just out of curiosity really. I had a struct, requirements
changed and I needed to inherit from it, so I made it into a class.

After the change, XmlSerializer choked because XmlSerializable classes
require a default constructor. Why don't structs?

Jun 19 '06 #2
Structs DO have constructors, but I found an answer with a quick
Google. In case anyone else is sad enough to care, structs have an
explicit but hidden default constructor whose purpose is to assign
default values to field members.

That's why you can't create an explicit default constructor on a
struct, the .Net framework creates one under the covers. This default
constructor is presumably used by the XmlSerializer.

Mystery solved.
bruce barker (sqlwork.com) wrote:
structs are not objects, but rather a value types. they are allocated on the
stack, rather than the heap. to improve value type performance, they do not
have contructors like objects.

-- bruce (sqlwork.com)

"Flinky Wisty Pomm" <Pa********@gmail.com> wrote in message
news:11**********************@r2g2000cwb.googlegro ups.com...
Hi, this is just out of curiosity really. I had a struct, requirements
changed and I needed to inherit from it, so I made it into a class.

After the change, XmlSerializer choked because XmlSerializable classes
require a default constructor. Why don't structs?


Jun 20 '06 #3

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

Similar topics

4
by: news.microsoft.com | last post by:
Hi, I am using structs and am also using property accessors to access those private member fields... TO me this is a good way of handling them, but I find alot of people using direct access to...
19
by: Jasper Kent | last post by:
Can anyone explain the logic behind structs being allowed neither memeber initialisers or default constructors. Doesn't this just encourage developers to create constructors with dummy...
2
by: mario.demiguel | last post by:
Does the standard support structs have constructors?
1
by: Pieter | last post by:
Hi, In my application VB.NET 2005 application I placed a ReportViewer, and link it to a server-report: Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote...
9
by: Peter Oliphant | last post by:
I've been told that value structs can have default constructors (I'm using VS C++.NET 2005 PRO using clr:/pure syntax). But the following code generates the following error: value struct...
12
by: Ole Nielsby | last post by:
Why is this? I've stumbled on this restriction more than once, and I'd like to know the philosophy behind it if there is one. I figure I'd be less prone to make this error if I knew the reason....
7
by: Markus Svilans | last post by:
Hi, What is the difference between having a struct with constructors and methods versus a class? In many C++ examples online I have seen code similar to this: struct Animal { Animal()
43
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...
6
by: =?Utf-8?B?QW5kcmV3X2QxMjM=?= | last post by:
Here is my problem. I have an app that has over 9 web services. For years I had not issues with clickonce but now it looks like the build is missing XmlSerializers.dll.deploy. I did have this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...

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.