Tuesday, November 02, 2004

VJs Tip Of The Day - November 2nd 2004

Why A HashTable Cannot be Xml Serialized

Javeed has posted the below question and it was probably a well asked question... Please read the mail below...

-----Original Message-----
From: Javeed Shaikh
Sent: Tuesday, November 02, 2004 10:17 PM
To: Vishal_Joshi@MVPs.org
Subject: Re: VJs Tip Of The Day

Hi Vishal,

I would like to know why a HashTable cannot be serialized?. Answer should be other than it is not inherited from some Interface, because this is the answer i got from many forums but no satisfactory answer.

Kind Regards

Javeed

Answer
There are many classes in .Net which cannot be xml serialized and they have their own reasons behind it... Ofcourse the default answer to a question -Why a particular class is not getting serialized? Is that it does not implement ISerializable, but it is good sometimes to reason out why did the .net class library team not implement ISerializable for them and many a times even if ISerializable is implemented why does Xml Serialization still is not truly functional for these classes... Wouldn't it be nice to have all the framework data carrying classes serializable (let's not get into this!!)... Well, here is the reason for Hashtable... The reason can be tweaked and extended to members which implement IDictionary...
For members with indexers XmlSerializer expects the index to be an integer, in case of hash-table its a key-value pair and thus not necessarily an integer... This makes the default HashTable not serializable for XmlSerializer...
Thus calling the below method will throw an error at the text marked bold...

Imports System.IO
Imports System.Xml.Serialization
Class DoSerialization...
Public Sub Serialize(ByVal hst As Hashtable)
Dim serializer As New XmlSerializer(GetType(Hashtable))
Dim writer As New StreamWriter("C:\Hastable.xml")
serializer.Serialize(writer, hst)
End Sub

The error thrown in the above code will be:
"An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll
Additional information: There was an error reflecting 'System.Collections.Hashtable"

and now perhaps the reason must be evident as to why there is a reflecting error...

How do you work around for this problem... Easy way would be to copy the content of the hash table into something that is serializable (e.g. array) and then on the other end again deserialize the same back into a hash table if it is that important to use a hash table... :-)

Further comments are invited...

PS: There have been rumors about MS Student Ambassadors being paid and doing favored jobs for Microsoft for personal benefits... Folks like Student Ambassadors, Community Stars, MVPs etc are volunteers who are passionate about their respective technologies and so are evangelists for the same, they do not expect anything in return... A very active student ambassador named Sriram Krishnan, who is associated with CNUGStudent and other community activities has replied on one such allegation... Me and many others in the MVP community had appreciated Sriram's mail and I requested him to allow the mail transcripts to be posted on the blog... Below are the details (read from bottom up)...

-----Original Message-----
From: Sriram Krishnan
Sent: Tuesday, November 02, 2004 1:48 AM
To: 'Vishal Joshi'
Subject: RE: request

Go ahead - its time people heard our side of the story. And thanks for the kind words - nice to know that all you guys are there to back me up :-)

Sriram

-----Original Message-----
From: Sriram Krishnan [mailto:ksriram@gmx.net]
Sent: 01 November 2004 13:17
To: 'rms@gnu.org'
Subject: Microsoft Student Ambassadors and .NET presentations

Hi,

A friend of mine forwarded me your views on Microsoft Student
Ambassadors and .NET sessions. I'm one of the Microsoft Student
Ambassadors involved in this and I wanted to reply to
clear up some of the misconceptions in the original mail. But I thought an intro on MSAs and that we do would be appropriate.
Before anything else, let me state that I have huge
respect for the GNU movement and for you personally. I do not want to enter into any argument on our differing views- but rather give you the full story as I fear you have formed a opinion without having all the facts. I admit that my views differ - but I am a technology
enthusiast and I run 2 different GNU/Linux distros at home . So by no means am I a
'M$ spy'. Microsoft roped me in as a student ambassador after seeing some of efforts to spread technology awareness. They do not pay me in any way - apart from the odd t-shirt and CD, everything we do is on our own and is not motivated by any benefit from
Microsoft. And I'm not looking for a job there either - I've already got a job in an Indian company which I plan to take up when I finish college. By the way, Microsoft is deceiving people when they say this is an open standard", since in the US they are trying to patent some
aspects of it. It could be useful to bring that up and expose it.
I'm not sure whether you've been told the entire story. We never wanted to do a session on Microsoft .NET. It would be *highly* improper for us to talk about any proprietary software in a GLUG meeting. I have no intention of doing that. What I wanted to talk about was Mono - as we felt that the Mono license was good enough for the meeting.I admire Miguel and his team and the work they are doing. However, we were told that Mono was not acceptable
as though the license is ok, it is *tainted* as Microsoft is behind the original technology. I totally understand that logic and would have been happy to let it go if that logic had been followed without any break. However, this same group had recently had a session on
Java, whose roots are definitely not free and Sun, to this date, hasn't published their source code. What I ask is - why the double standards? Isn't proprietary software unacceptable at a GLUG meeting? Why allow a demo of Java but not a demo of Mono?
We were asked to do a session on DotGNU. I personally disagree with some of the things that the DotGNU page says and Mono is the better-known of the two. When I wanted to have a debate about this on the mailing list(which ballooned into a flame war) or during the
session itself, I was told to go pound sand and not to send any more mails on the topic. The moderator wasn't even interested in listening to the views of the members as a lot of members did express an interest in Mono.I'm very disappointed that a GNU group doesn't believe in hearing other people's opinions and in rational debate.
Let me make something very clear - at no point was I talking about Microsoft or any proprietary software. I talked and intended to talk only of Mono and of its license and the Mono teams views (from their faq page). I understand that you and several others have reservations over Microsoft's ECMA standards. However Sun's Java process is not even an open standard - so why allow Java and show me the door?

From what you are saying, it sounds like they are starting phony "open source" groups. Can you find any specific statements that you can quote? We could embarrass them badly by documenting this, but we need specific quotes, specific proof.

You are very right in asking for proof. I am well-aware of the differences between open source and proprietary software. What we form are usergroups, not too different from the communities you see on Usenet , or Apple Mac fans, for example. Every month or so, we ( a bunch of .NET enthusiasts) meet at a place where one of us takes a session on some aspect of .NET. I try and encourage people not familiar with .NET to come and attend. Let me make one thing *very*
clear - we do not call ourselves an 'open' group or try to pretend to be something we're not. We want people to attend who know fully well what kind of sessions they're attending. I do not have any intention of trying to fool or misguide people by calling our groups 'open' or calling Microsoft software 'open source'. I do talk about Rotor and Microsoft's Shared Source License.
However,I know that the SSCLI is not a license that is accepted by the FSF. I do not fool people by telling them that it is an 'open source' license. In fact, during my sessions, I highlight
the part of the license where it says people cannot make any commercial
profit and other key differences between this and the GPL. We do not want people to think that Shared Source is something it is not - we want people to only use Shared Source only when they *completely* understand what the license is about. I have at no point of time
called Rotor as 'free software' - what I have said is that 'Rotor is a free download' which is meant to inform students that they don't have to pay to download it. IANAL, and I tell students that the Shared Source license and the GPL are very different and then encourage them to find out the specifics for themselves. And at no point in my sessions do I deride the GPL or any other open source license or claim that the SSCLI is better. I want to tell people what it is and that it is out there - people can make an informed choice for themselves.

There is nothing phony about us or in our love for technology. I understand that you may not agree - but please do understand that I'm not a thief or a spy trying to fool people. I've asked Joe Steeve (the moderator of the GLUG-Madurai) to attend our sessions to see for himself
what we talk about but he hasn't turned up once. However, as someone who has done
over 10-15 of these sessions, let me assure you that these sessions are usually about some intricate aspect of .NET and the only time we've spoken of GNU/Linux is when people have asked us whether .NET can be run on Linux.

2. Recruit a couple of people to pretend to be interested in joining, go to the meeting, and speak up within it to identify the lies.
I have been saying this for a long time. I try and encourage discussion and debate in our group and would love to have other points of views. However, I'm afraid they won't see any choice quotes bashing GNU/Linux or the Free software movement. What they'll see is a *lot* of technical information on Microsoft software.

4. Treat the MSA program and its representatives as liars. Don't treat them as respectable or legitimate.
I object to this - how have I lied? Our opinions differ , yes. But I do not try to fool people. And the original mail had accused me of lying - I would like to see some proof of this 'lying'. Proprietary software nutcase I may be, spy or liar, I am not.

I regret that you have been pulled into this and not been given the whole story. I do not agree with some of the things the FSF says,but I do not think that means I'm a liar or evil in some
way.I sent you this mail as I'm highly saddened that someone I admire a lot and someone whose work I use everyday(I'm an Emacs fan) has branded me without getting all the facts.
It is possible I am misguided - I am only 20 years old. But I'm not consciously trying to harm anyone or fool anyone.

Thanks,
Sriram



-------- Original Message --------
From: Richard Stallman
A MSA who was pestering me for a DotNET session at
GLUG-Madurai argued that DotNET being an Open Standard, I should not
object him promoting it in the GLUG.

When he said this, he was taking advantage of a broader
misunderstanding. The idea of GNU/Linux is to be free
software; "open standard", even if that is true, is not good
enough if the software itself is non-free.

So it looks like we need to educate all GLUGs (and
LUGs, if they will listen) to recognize and teac that people should not promote
non-free software--regardless of the details.

By the way, Microsoft is deceiving people when they say
this is an "open standard", since in the US they are trying to patent some
aspects of it. It could be useful to bring that up and
expose it.

The lesson that I learn from these people is to
outrightly reject their requests. They are not worth the trouble.

We should always refuse to give developers of non-free
software a platform to speak. However, saying that this is "not worth the
trouble" is misleading, because it is implies there is some
potential good to be achieved--if only it were easier to do.

What they are doing is bad, pure and simple. There is
no good in it.

M$ through its Micro$oft Student Ambassadors
is doing a large scale mobilisation in colleges amongst the
student community. They wrap their stuff under
labels such as "M$s Open Source venture", "Open Technology", etc..
They are forming student groups in colleges.

From what you are saying, it sounds like they are
starting phony "open source" groups. Can you find any specific statements
that you can quote? We could embarrass them badly by documenting
this, but we need specific quotes, specific proof.

If you could go to a meeting where they try to recruit
new people, and make a recording so that you can quote them exactly, that
would be useful too.

Once we have solid proof, we could use various methods
to organize against them.

1. Make handouts denouncing them as a fraud. Whenever
they have an event, a few of you can stand near the door and hand
out copies to whoever is attending. In effect, stage a quiet and simple
protest against each of their meetings, accusing them of lying.

2. Recruit a couple of people to pretend to be interested in
joining, go to the meeting, and speak up within it to identify the lies.

3. Write articles for student newspapers about the deception.

4. Treat the MSA program and its representatives as liars.
Don't treat them as respectable or legitimate.

5. Call on the university to close the program down for lying.
Even if this campaign does not succeed, it will generate public
awareness that will be useful in all ways. So renew the campaign each
year!




1 comment:

Anonymous said...

I came across you blog and thought you may find this site usefull. It has gas saving tips and where to find cheap gas. travel

:)