473,392 Members | 1,319 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,392 software developers and data experts.

Derived Dictionary serialization: please help me find the error in this simple code snippet


Hi, please find below a very simple code snippet which is giving me
the following error:

System.Runtime.Serialization.SerializationExceptio n was unhandled
Message="The constructor to deserialize an object of type
'WindowsApplication10.Form1+DictionaryExt`2[System.String,WindowsApplication10.Form1+WhateverC lass]'
was not found."
Source="mscorlib"

You can just past the snippet on any form with a button.

Could anyone please point out how I can correct the code below.
I must be missing something simple, but I can't see what.
How do I specify the "deserialization constructor"?

Thanks.
PS
Also what is " DictionaryExt`2 ", there is no symbol with such a name
in the snippet !?

------------------------------ CODE
--------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
DictionaryExt<string, WhateverClassMyDictionaryExt = new
DictionaryExt<string,
WhateverClass>(StringComparer.InvariantCultureIgno reCase);
//Serialization
DictionaryExt<string, WhateverClassClone =
(DictionaryExt<string,
WhateverClass>)CloneObjectInMemory(MyDictionaryExt );
}
public object CloneObjectInMemory(object MyObject)
{
using (System.IO.MemoryStream MemoryStream = new
System.IO.MemoryStream()) {
{
new
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter().Serialize(MemoryStream,
MyObject);
MemoryStream.Position = 0;
return new
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter().Deserialize(MemoryStream);
}
}
}

[Serializable()]
public class DictionaryExt<Key, value:
System.Collections.Generic.Dictionary<Key, value>
{

public DictionaryExt(IEqualityComparer<KeyIEqualityCompar er)
: base(IEqualityComparer)
{
}
}

public class WhateverClass
{
public string Greeting = "Hi";
public int Age;
}

}
}

Feb 12 '07 #1
6 3804
if you want a serializable (xml) dictionary why not try

http://weblogs.asp.net/pwelter34/arc...03/444961.aspx

HTH

Ollie Riches

"pamela fluente" <pa***********@libero.itwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
>
Hi, please find below a very simple code snippet which is giving me
the following error:

System.Runtime.Serialization.SerializationExceptio n was unhandled
Message="The constructor to deserialize an object of type
'WindowsApplication10.Form1+DictionaryExt`2[System.String,WindowsApplication10.Form1+WhateverC lass]'
was not found."
Source="mscorlib"

You can just past the snippet on any form with a button.

Could anyone please point out how I can correct the code below.
I must be missing something simple, but I can't see what.
How do I specify the "deserialization constructor"?

Thanks.
PS
Also what is " DictionaryExt`2 ", there is no symbol with such a name
in the snippet !?

------------------------------ CODE
--------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
DictionaryExt<string, WhateverClassMyDictionaryExt = new
DictionaryExt<string,
WhateverClass>(StringComparer.InvariantCultureIgno reCase);
//Serialization
DictionaryExt<string, WhateverClassClone =
(DictionaryExt<string,
WhateverClass>)CloneObjectInMemory(MyDictionaryExt );
}
public object CloneObjectInMemory(object MyObject)
{
using (System.IO.MemoryStream MemoryStream = new
System.IO.MemoryStream()) {
{
new
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter().Serialize(MemoryStream,
MyObject);
MemoryStream.Position = 0;
return new
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter().Deserialize(MemoryStream);
}
}
}

[Serializable()]
public class DictionaryExt<Key, value:
System.Collections.Generic.Dictionary<Key, value>
{

public DictionaryExt(IEqualityComparer<KeyIEqualityCompar er)
: base(IEqualityComparer)
{
}
}

public class WhateverClass
{
public string Greeting = "Hi";
public int Age;
}

}
}

Feb 12 '07 #2
On 12 Feb, 15:57, "Ollie Riches" <ollie_ric...@hotmail.comwrote:
if you want a serializable (xml) dictionary why not try

http://weblogs.asp.net/pwelter34/arc...03/444961.aspx
Thanks Ollie ,

as you can see I am doing *binary* serialization, not XML.

In any case, I need to understand well the problem here, because
actually this is
just an example of several colllections I am deriving and that have
the same issue.

So what's the real problem here and what's the code correction ?

Any help ?
-Pam

Feb 12 '07 #3
you aree going to require a binary deserialization constructor as well as an
implementation of the interface method GetObjectData() on your dictionary
class.

a vb.net example

http://www.knowdotnet.com/articles/e...alization.html

HTH

Ollie Riches

"pamela fluente" <pa***********@libero.itwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
On 12 Feb, 15:57, "Ollie Riches" <ollie_ric...@hotmail.comwrote:
>if you want a serializable (xml) dictionary why not try

http://weblogs.asp.net/pwelter34/arc...03/444961.aspx

Thanks Ollie ,

as you can see I am doing *binary* serialization, not XML.

In any case, I need to understand well the problem here, because
actually this is
just an example of several colllections I am deriving and that have
the same issue.

So what's the real problem here and what's the code correction ?

Any help ?
-Pam

Feb 12 '07 #4
On 12 Feb, 15:57, "Ollie Riches" <ollie_ric...@hotmail.comwrote:
if you want a serializable (xml) dictionary why not try

http://weblogs.asp.net/pwelter34/arc...03/444961.aspx

HTH

Ollie Riches
Thanks Ollie ,

I have been serializing several objects and I know serialization
basics.

Before I used collections such us hashtables, or Sorted List and I
never had any problem.

Here I am not clear what is the problem Why a typed collection needs a
constructor
while a not typed one doesn't ? It would seem to me that a typed
collection should store more information.

So actually I am lost here, and the examples I have seen so far do not
spread any light ! :-(

Does anyone have an example to understand what is going on here ?
Can anyone show the actual code corrections to my simple snippet ?

-Pam

Feb 12 '07 #5
On 12 Feb 2007 07:59:03 -0800, "pamela fluente"
<pa***********@libero.itwrote:
>On 12 Feb, 15:57, "Ollie Riches" <ollie_ric...@hotmail.comwrote:
>if you want a serializable (xml) dictionary why not try

http://weblogs.asp.net/pwelter34/arc...03/444961.aspx

HTH

Ollie Riches

Thanks Ollie ,

I have been serializing several objects and I know serialization
basics.

Before I used collections such us hashtables, or Sorted List and I
never had any problem.

Here I am not clear what is the problem Why a typed collection needs a
constructor
while a not typed one doesn't ? It would seem to me that a typed
collection should store more information.

So actually I am lost here, and the examples I have seen so far do not
spread any light ! :-(

Does anyone have an example to understand what is going on here ?
Can anyone show the actual code corrections to my simple snippet ?

-Pam
Couple of thoughts:

Doesn't deserialization always require a parameterless constructor?
Your class doesn't have one. However, adding one doesn't fix the
problem I am afraid!

I suspect that somehow you need to tell deserialize the type
parameters used to instantiate the generic. There must be some code
out on the net that does that. This might be a good starting point
http://groups.google.com/group/micro...3ca1777cf82674

--
Philip Daniels
Feb 13 '07 #6
Phil, you only need a parameterless constructor for xml serialisation.

Ollie Riches
<Ph***********@foo.comwrote in message
news:1f********************************@4ax.com...
On 12 Feb 2007 07:59:03 -0800, "pamela fluente"
<pa***********@libero.itwrote:
>>On 12 Feb, 15:57, "Ollie Riches" <ollie_ric...@hotmail.comwrote:
>>if you want a serializable (xml) dictionary why not try

http://weblogs.asp.net/pwelter34/arc...03/444961.aspx

HTH

Ollie Riches

Thanks Ollie ,

I have been serializing several objects and I know serialization
basics.

Before I used collections such us hashtables, or Sorted List and I
never had any problem.

Here I am not clear what is the problem Why a typed collection needs a
constructor
while a not typed one doesn't ? It would seem to me that a typed
collection should store more information.

So actually I am lost here, and the examples I have seen so far do not
spread any light ! :-(

Does anyone have an example to understand what is going on here ?
Can anyone show the actual code corrections to my simple snippet ?

-Pam

Couple of thoughts:

Doesn't deserialization always require a parameterless constructor?
Your class doesn't have one. However, adding one doesn't fix the
problem I am afraid!

I suspect that somehow you need to tell deserialize the type
parameters used to instantiate the generic. There must be some code
out on the net that does that. This might be a good starting point
http://groups.google.com/group/micro...3ca1777cf82674

--
Philip Daniels

Feb 13 '07 #7

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

Similar topics

10
by: Stefan Seefeld | last post by:
hi there, I'm trying to convert a tuple to a list, and get a 'TypeError: list objects are unhashable'. Can anybody enlighten me as to the possible causes for this ? Where does hashing come...
3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
0
by: big A | last post by:
I am receiving an error stating that File or Assembly name <filname.dll>, or one of its dependencies, was not found In one assembly I have three abstract classes In another I have three...
5
by: Tamir Khason | last post by:
I have an object (eg MyObject with namespace eg MyNamespace) public class MyObject While I serialize it the XML created is <MyObject xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
2
by: jg | last post by:
I was trying to get custom dictionary class that can store generic or string; So I started with the example given by the visual studio 2005 c# online help for simpledictionay object That seem...
3
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one...
6
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The...
1
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...

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.