P
pamela fluente
Hi, please find below a very simple code snippet which is giving me
the following error:
System.Runtime.Serialization.SerializationException was unhandled
Message="The constructor to deserialize an object of type
'WindowsApplication10.Form1+DictionaryExt`2[System.String,WindowsApplication10.Form1+WhateverClass]'
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, WhateverClass> MyDictionaryExt = new
DictionaryExt<string,
WhateverClass>(StringComparer.InvariantCultureIgnoreCase);
//Serialization
DictionaryExt<string, WhateverClass> Clone =
(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.BinaryFormatter().Serialize(MemoryStream,
MyObject);
MemoryStream.Position = 0;
return new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Deserialize(MemoryStream);
}
}
}
[Serializable()]
public class DictionaryExt<Key, value> :
System.Collections.Generic.Dictionary<Key, value>
{
public DictionaryExt(IEqualityComparer<Key> IEqualityComparer)
: base(IEqualityComparer)
{
}
}
public class WhateverClass
{
public string Greeting = "Hi";
public int Age;
}
}
}
the following error:
System.Runtime.Serialization.SerializationException was unhandled
Message="The constructor to deserialize an object of type
'WindowsApplication10.Form1+DictionaryExt`2[System.String,WindowsApplication10.Form1+WhateverClass]'
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, WhateverClass> MyDictionaryExt = new
DictionaryExt<string,
WhateverClass>(StringComparer.InvariantCultureIgnoreCase);
//Serialization
DictionaryExt<string, WhateverClass> Clone =
(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.BinaryFormatter().Serialize(MemoryStream,
MyObject);
MemoryStream.Position = 0;
return new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Deserialize(MemoryStream);
}
}
}
[Serializable()]
public class DictionaryExt<Key, value> :
System.Collections.Generic.Dictionary<Key, value>
{
public DictionaryExt(IEqualityComparer<Key> IEqualityComparer)
: base(IEqualityComparer)
{
}
}
public class WhateverClass
{
public string Greeting = "Hi";
public int Age;
}
}
}