473,756 Members | 4,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.S erializationExc eption was unhandled
Message="The constructor to deserialize an object of type
'WindowsApplica tion10.Form1+Di ctionaryExt`2[System.String,W indowsApplicati on10.Form1+What everClass]'
was not found."
Source="mscorli b"

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 "deserializatio n constructor"?

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

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

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace WindowsApplicat ion10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}

private void button1_Click(o bject sender, EventArgs e)
{
DictionaryExt<s tring, WhateverClassMy DictionaryExt = new
DictionaryExt<s tring,
WhateverClass>( StringComparer. InvariantCultur eIgnoreCase);
//Serialization
DictionaryExt<s tring, WhateverClassCl one =
(DictionaryExt< string,
WhateverClass>) CloneObjectInMe mory(MyDictiona ryExt);
}
public object CloneObjectInMe mory(object MyObject)
{
using (System.IO.Memo ryStream MemoryStream = new
System.IO.Memor yStream()) {
{
new
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er().Serialize( MemoryStream,
MyObject);
MemoryStream.Po sition = 0;
return new
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er().Deserializ e(MemoryStream) ;
}
}
}

[Serializable()]
public class DictionaryExt<K ey, value:
System.Collecti ons.Generic.Dic tionary<Key, value>
{

public DictionaryExt(I EqualityCompare r<KeyIEqualityC omparer)
: base(IEqualityC omparer)
{
}
}

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

}
}

Feb 12 '07 #1
6 3826
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.goo glegroups.com.. .
>
Hi, please find below a very simple code snippet which is giving me
the following error:

System.Runtime. Serialization.S erializationExc eption was unhandled
Message="The constructor to deserialize an object of type
'WindowsApplica tion10.Form1+Di ctionaryExt`2[System.String,W indowsApplicati on10.Form1+What everClass]'
was not found."
Source="mscorli b"

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 "deserializatio n constructor"?

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

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

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace WindowsApplicat ion10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}

private void button1_Click(o bject sender, EventArgs e)
{
DictionaryExt<s tring, WhateverClassMy DictionaryExt = new
DictionaryExt<s tring,
WhateverClass>( StringComparer. InvariantCultur eIgnoreCase);
//Serialization
DictionaryExt<s tring, WhateverClassCl one =
(DictionaryExt< string,
WhateverClass>) CloneObjectInMe mory(MyDictiona ryExt);
}
public object CloneObjectInMe mory(object MyObject)
{
using (System.IO.Memo ryStream MemoryStream = new
System.IO.Memor yStream()) {
{
new
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er().Serialize( MemoryStream,
MyObject);
MemoryStream.Po sition = 0;
return new
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er().Deserializ e(MemoryStream) ;
}
}
}

[Serializable()]
public class DictionaryExt<K ey, value:
System.Collecti ons.Generic.Dic tionary<Key, value>
{

public DictionaryExt(I EqualityCompare r<KeyIEqualityC omparer)
: base(IEqualityC omparer)
{
}
}

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

}
}

Feb 12 '07 #2
On 12 Feb, 15:57, "Ollie Riches" <ollie_ric...@h otmail.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.goog legroups.com...
On 12 Feb, 15:57, "Ollie Riches" <ollie_ric...@h otmail.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...@h otmail.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...@h otmail.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.c om...
On 12 Feb 2007 07:59:03 -0800, "pamela fluente"
<pa***********@ libero.itwrote:
>>On 12 Feb, 15:57, "Ollie Riches" <ollie_ric...@h otmail.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
4750
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 into play during this conversion ? Could it be that my runtime is corrupted ?
3
6576
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? Here's what I'm generally trying to achieve: I'm building (trying to anyway) a serialization library. Here's my design:
0
2493
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 derived classes from the abstract classes The 1st class contains the 2nd class The 2nd class is a custom collection for the 3rd class
5
3246
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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="MyNamespace">
5
2825
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 like it to return an XML serialized version of an object.
2
3424
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 to miss a few things including #endregion directive and the ending class } Is there not a simple way like in dotnet vb? I managed to get the sample to code to this:
3
8088
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 statement to VB.NET and this is crucial: re-implementing ISerializable.GetObjectData() in the DataTable derived class so serializing the datatable derived class will call this method and not the DataTable version (which is private, so overriding is also...
6
6055
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 problem is that in my derived classes, the XML that is automatically generated is lacking the properties of the base class. For example: public class MyBaseClass { public MyBaseClass ( ) { } private string myVariable;
1
5122
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 version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:myns="uri:myschema" targetNamespace="uri:myschema" elementFormDefault="qualified" version="1.0"> <xs:complexType name="derivedProperty">
0
9431
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
9255
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
10014
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
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...
1
9819
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7226
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
6514
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3780
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 we have to send another system
3
2647
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.