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.
the class of the object is defined serializable as the following:
[Serializable]
public class Event
{
}
Also it contains 5 properties returning simple data type such as int and
string. But one of them is an Hashtable. When I run my project i got a run
time exception telling me that :
System.InvalidOperationException: There was an error reflecting type
'Bos.BizObj.Event'. ---> System.NotSupportedException: The type
System.Collections.Hashtable is not supported because it implements
IDictionary.
at System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type type)
Then my question is:
How can I make the Hashtable serializable to make in turn my Event class
serializable?
Also I am a little bit surprised as in the .Net framework reference it is
specified that the
Hashtable class implement the serializable interface... Then it is puzzling
me even more.
Thanks a lot,
Francois 5 2803
Posting again. Try not to repost the same message more then once.
Regards,
---------------------------------------
using System;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace ConsoleApplication5
{
[Serializable]
struct name
{
public string forname;
public string familyname;
}
[Serializable]
struct address
{
public string street;
public int number;
}
class clsDataBlock
{
public static Hashtable NameToAddress = new Hashtable ();
[STAThread]
static void Main(string[] args)
{
clsDataBlock db=new clsDataBlock ();
string ans="";
while("x" != ans)
{
System.Console.WriteLine ("1 to enter new");
System.Console.WriteLine ("2 to search");
System.Console.WriteLine ("3 to save (serialize)");
System.Console.WriteLine ("4 to load (deserialize)");
System.Console.WriteLine ("5 to show data");
System.Console.WriteLine ("x to quit");
System.Console.WriteLine ("-----------------------");
ans = System.Console.ReadLine ();
switch(ans)
{
case "1":db.AddNew();
break;
case "2":db.Search();
break;
case "3":db.Save();
break;
case "4":db.Load();
break;
case "5":db.Show();
break;
}
}
}
public void AddNew()
{
name nm;
address ad;
string ans;
System.Console.WriteLine ("enter first name (x to exit):");
ans = System.Console.ReadLine();
nm.forname = ans;
System.Console.WriteLine ("enter last name (x to exit):");
ans = System.Console.ReadLine();
nm.familyname = ans;
System.Console.WriteLine ("enter street name (x to exit):");
ans = System.Console.ReadLine();
ad.street = ans;
System.Console.WriteLine ("enter street number (x to exit):");
ans = System.Console.ReadLine();
ad.number = int.Parse (ans);
NameToAddress.Add(nm,ad);
}
public void Search()
{
name nm2;
string ans2;
System.Console.WriteLine ("enter first name:");
ans2 = System.Console.ReadLine ();
nm2.forname = ans2;
System.Console.WriteLine ("enter last name:");
ans2 = System.Console.ReadLine ();
nm2.familyname = ans2;
System.Console.WriteLine ("working...");
object sname = NameToAddress[nm2];
if (sname != null)
{
address ad2 = (address)sname;
System.Console.WriteLine(" address: "+ ad2.street + " " +
ad2.number );
}
else
System.Console.WriteLine ("no name like that...");
}
public void Save()
{
FileStream fs = new FileStream ("Store.dat",FileMode.OpenOrCreate
,FileAccess.Write );
try
{
Hashtable a = new Hashtable();
a = NameToAddress;
BinaryFormatter bf=new BinaryFormatter ();
bf.Serialize (fs,a );
}
finally
{
fs.Close ();
}
}
public void Load()
{
FileStream fs = new FileStream ("Store.dat",FileMode.Open
,FileAccess.Read );
try
{
Hashtable a = new Hashtable();
BinaryFormatter bf=new BinaryFormatter ();
a=(Hashtable)bf.Deserialize (fs);
NameToAddress = a;
}
finally
{
fs.Close ();
}
}
public void Show()
{
name nm3;
address ad3;
foreach (DictionaryEntry entry in NameToAddress )
{
nm3 = (name)entry.Key;
ad3 = (address)entry.Value;
Console.WriteLine ("name= {0} {1}, address= {2} {3}",
nm3.forname,nm3.familyname ,ad3.street ,ad3.number);
}
}
}
}
Hope it helps
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message
news:OE**************@TK2MSFTNGP12.phx.gbl... Hi,
I have a webservice that I am using and I would like it to return an XML serialized version of an object.
the class of the object is defined serializable as the following:
[Serializable] public class Event { }
Also it contains 5 properties returning simple data type such as int and string. But one of them is an Hashtable. When I run my project i got a run time exception telling me that :
System.InvalidOperationException: There was an error reflecting type 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type System.Collections.Hashtable is not supported because it implements IDictionary. at System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type type)
Then my question is: How can I make the Hashtable serializable to make in turn my Event class serializable?
Also I am a little bit surprised as in the .Net framework reference it is specified that the Hashtable class implement the serializable interface... Then it is
puzzling me even more
Thanks a lot,
Francois
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message
news:O9*************@TK2MSFTNGP11.phx.gbl... 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.
the class of the object is defined serializable as the following:
[Serializable] public class Event { }
Also it contains 5 properties returning simple data type such as int and string. But one of them is an Hashtable. When I run my project i got a run time exception telling me that :
System.InvalidOperationException: There was an error reflecting type 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type System.Collections.Hashtable is not supported because it implements IDictionary. at System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type type)
Then my question is: How can I make the Hashtable serializable to make in turn my Event class serializable?
Also I am a little bit surprised as in the .Net framework reference it is specified that the Hashtable class implement the serializable interface... Then it is
puzzling me even more.
Thanks a lot,
Francois
The problem is that I think your code is not related to my question, I found
the same code doing a google search - http://radio.weblogs.com/0111551/sto...erialized.html
- and it is not helping me in my situation, then before posting stuff, make
sure you answer the question, if you cannot answer, just let a chance for
someone to do it.
Tx
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:eO**************@TK2MSFTNGP10.phx.gbl... Posting again. Try not to repost the same message more then once.
Regards, ---------------------------------------
using System;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace ConsoleApplication5
{
[Serializable]
struct name
{
public string forname;
public string familyname;
} [Serializable]
struct address
{
public string street;
public int number;
} class clsDataBlock
{ public static Hashtable NameToAddress = new Hashtable (); [STAThread]
static void Main(string[] args)
{
clsDataBlock db=new clsDataBlock ();
string ans=""; while("x" != ans)
{
System.Console.WriteLine ("1 to enter new");
System.Console.WriteLine ("2 to search");
System.Console.WriteLine ("3 to save (serialize)");
System.Console.WriteLine ("4 to load (deserialize)");
System.Console.WriteLine ("5 to show data");
System.Console.WriteLine ("x to quit");
System.Console.WriteLine ("-----------------------"); ans = System.Console.ReadLine (); switch(ans)
{
case "1":db.AddNew();
break;
case "2":db.Search();
break;
case "3":db.Save();
break;
case "4":db.Load();
break;
case "5":db.Show();
break;
}
}
}
public void AddNew()
{
name nm;
address ad;
string ans;
System.Console.WriteLine ("enter first name (x to exit):");
ans = System.Console.ReadLine();
nm.forname = ans; System.Console.WriteLine ("enter last name (x to exit):");
ans = System.Console.ReadLine();
nm.familyname = ans; System.Console.WriteLine ("enter street name (x to exit):");
ans = System.Console.ReadLine();
ad.street = ans; System.Console.WriteLine ("enter street number (x to exit):");
ans = System.Console.ReadLine();
ad.number = int.Parse (ans); NameToAddress.Add(nm,ad);
} public void Search()
{
name nm2; string ans2;
System.Console.WriteLine ("enter first name:");
ans2 = System.Console.ReadLine ();
nm2.forname = ans2; System.Console.WriteLine ("enter last name:");
ans2 = System.Console.ReadLine ();
nm2.familyname = ans2; System.Console.WriteLine ("working..."); object sname = NameToAddress[nm2];
if (sname != null)
{
address ad2 = (address)sname;
System.Console.WriteLine(" address: "+ ad2.street + " " + ad2.number );
}
else
System.Console.WriteLine ("no name like that..."); } public void Save()
{
FileStream fs = new FileStream ("Store.dat",FileMode.OpenOrCreate ,FileAccess.Write );
try
{
Hashtable a = new Hashtable();
a = NameToAddress;
BinaryFormatter bf=new BinaryFormatter ();
bf.Serialize (fs,a );
}
finally
{
fs.Close ();
}
}
public void Load()
{
FileStream fs = new FileStream ("Store.dat",FileMode.Open ,FileAccess.Read );
try
{
Hashtable a = new Hashtable();
BinaryFormatter bf=new BinaryFormatter ();
a=(Hashtable)bf.Deserialize (fs);
NameToAddress = a;
}
finally
{
fs.Close ();
}
}
public void Show()
{
name nm3;
address ad3;
foreach (DictionaryEntry entry in NameToAddress )
{
nm3 = (name)entry.Key;
ad3 = (address)entry.Value;
Console.WriteLine ("name= {0} {1}, address= {2} {3}",
nm3.forname,nm3.familyname ,ad3.street ,ad3.number);
}
}
}
} Hope it helps -- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message news:OE**************@TK2MSFTNGP12.phx.gbl... Hi,
I have a webservice that I am using and I would like it to return an XML serialized version of an object.
the class of the object is defined serializable as the following:
[Serializable] public class Event { }
Also it contains 5 properties returning simple data type such as int and string. But one of them is an Hashtable. When I run my project i got a
run time exception telling me that :
System.InvalidOperationException: There was an error reflecting type 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type System.Collections.Hashtable is not supported because it implements IDictionary. at System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type
type) Then my question is: How can I make the Hashtable serializable to make in turn my Event class serializable?
Also I am a little bit surprised as in the .Net framework reference it
is specified that the Hashtable class implement the serializable interface... Then it is puzzling me even more
Thanks a lot,
Francois
-- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message news:O9*************@TK2MSFTNGP11.phx.gbl... 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.
the class of the object is defined serializable as the following:
[Serializable] public class Event { }
Also it contains 5 properties returning simple data type such as int and string. But one of them is an Hashtable. When I run my project i got a
run time exception telling me that :
System.InvalidOperationException: There was an error reflecting type 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type System.Collections.Hashtable is not supported because it implements IDictionary. at System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type
type) Then my question is: How can I make the Hashtable serializable to make in turn my Event class serializable?
Also I am a little bit surprised as in the .Net framework reference it
is specified that the Hashtable class implement the serializable interface... Then it is puzzling me even more.
Thanks a lot,
Francois
The question was "How can I make the Hashtable serializable ", right? This
code snaplet is very famous in i-net, however if the answer can not halp
you, I'm sorry. Please provide exact situation and what you want to do?
If I'm using this code on your structure, it works fine without any
exception. So what is the problem?
Please help me and others to clarify and help you to solve it.
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message
news:OQ*************@TK2MSFTNGP12.phx.gbl... The problem is that I think your code is not related to my question, I
found the same code doing a google search - http://radio.weblogs.com/0111551/sto...erialized.html - and it is not helping me in my situation, then before posting stuff,
make sure you answer the question, if you cannot answer, just let a chance for someone to do it.
Tx
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message news:eO**************@TK2MSFTNGP10.phx.gbl... Posting again. Try not to repost the same message more then once.
Regards, ---------------------------------------
using System;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace ConsoleApplication5
{
[Serializable]
struct name
{
public string forname;
public string familyname;
} [Serializable]
struct address
{
public string street;
public int number;
} class clsDataBlock
{ public static Hashtable NameToAddress = new Hashtable (); [STAThread]
static void Main(string[] args)
{
clsDataBlock db=new clsDataBlock ();
string ans=""; while("x" != ans)
{
System.Console.WriteLine ("1 to enter new");
System.Console.WriteLine ("2 to search");
System.Console.WriteLine ("3 to save (serialize)");
System.Console.WriteLine ("4 to load (deserialize)");
System.Console.WriteLine ("5 to show data");
System.Console.WriteLine ("x to quit");
System.Console.WriteLine ("-----------------------"); ans = System.Console.ReadLine (); switch(ans)
{
case "1":db.AddNew();
break;
case "2":db.Search();
break;
case "3":db.Save();
break;
case "4":db.Load();
break;
case "5":db.Show();
break;
}
}
}
public void AddNew()
{
name nm;
address ad;
string ans;
System.Console.WriteLine ("enter first name (x to exit):");
ans = System.Console.ReadLine();
nm.forname = ans; System.Console.WriteLine ("enter last name (x to exit):");
ans = System.Console.ReadLine();
nm.familyname = ans; System.Console.WriteLine ("enter street name (x to exit):");
ans = System.Console.ReadLine();
ad.street = ans; System.Console.WriteLine ("enter street number (x to exit):");
ans = System.Console.ReadLine();
ad.number = int.Parse (ans); NameToAddress.Add(nm,ad);
} public void Search()
{
name nm2; string ans2;
System.Console.WriteLine ("enter first name:");
ans2 = System.Console.ReadLine ();
nm2.forname = ans2; System.Console.WriteLine ("enter last name:");
ans2 = System.Console.ReadLine ();
nm2.familyname = ans2; System.Console.WriteLine ("working..."); object sname = NameToAddress[nm2];
if (sname != null)
{
address ad2 = (address)sname;
System.Console.WriteLine(" address: "+ ad2.street + " " + ad2.number );
}
else
System.Console.WriteLine ("no name like that..."); } public void Save()
{
FileStream fs = new FileStream
("Store.dat",FileMode.OpenOrCreate ,FileAccess.Write );
try
{
Hashtable a = new Hashtable();
a = NameToAddress;
BinaryFormatter bf=new BinaryFormatter ();
bf.Serialize (fs,a );
}
finally
{
fs.Close ();
}
}
public void Load()
{
FileStream fs = new FileStream ("Store.dat",FileMode.Open ,FileAccess.Read );
try
{
Hashtable a = new Hashtable();
BinaryFormatter bf=new BinaryFormatter ();
a=(Hashtable)bf.Deserialize (fs);
NameToAddress = a;
}
finally
{
fs.Close ();
}
}
public void Show()
{
name nm3;
address ad3;
foreach (DictionaryEntry entry in NameToAddress )
{
nm3 = (name)entry.Key;
ad3 = (address)entry.Value;
Console.WriteLine ("name= {0} {1}, address= {2} {3}",
nm3.forname,nm3.familyname ,ad3.street ,ad3.number);
}
}
}
} Hope it helps -- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message news:OE**************@TK2MSFTNGP12.phx.gbl... Hi,
I have a webservice that I am using and I would like it to return an
XML serialized version of an object.
the class of the object is defined serializable as the following:
[Serializable] public class Event { }
Also it contains 5 properties returning simple data type such as int
and string. But one of them is an Hashtable. When I run my project i got a run time exception telling me that :
System.InvalidOperationException: There was an error reflecting type 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type System.Collections.Hashtable is not supported because it implements IDictionary. at System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type type) Then my question is: How can I make the Hashtable serializable to make in turn my Event
class serializable?
Also I am a little bit surprised as in the .Net framework reference it is specified that the Hashtable class implement the serializable interface... Then it is
puzzling me even more
Thanks a lot,
Francois
-- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message news:O9*************@TK2MSFTNGP11.phx.gbl... 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.
the class of the object is defined serializable as the following:
[Serializable] public class Event { }
Also it contains 5 properties returning simple data type such as int
and string. But one of them is an Hashtable. When I run my project i got a run time exception telling me that :
System.InvalidOperationException: There was an error reflecting type 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type System.Collections.Hashtable is not supported because it implements IDictionary. at System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type type) Then my question is: How can I make the Hashtable serializable to make in turn my Event
class serializable?
Also I am a little bit surprised as in the .Net framework reference it is specified that the Hashtable class implement the serializable interface... Then it is puzzling me even more.
Thanks a lot,
Francois
First of all thanks a lot and here i will go for more details but i am
afraid it may be a little bit lenghty.
This is the full definition of my class:
[Serializable]
public class Event
{
private int eventId;
private EventTypeId eventTypeId;
private EventActionId eventActionId;
private string parameter;
//private Hashtable hParameters;
public int EventId
{
get
{
return eventId;
}
}
public EventTypeId EventTypeID //EventTypeId is an enum of int type
{
get
{
return eventTypeId;
}
}
public EventActionId EventActionID //EventActionId is an enum of int
type
{
get
{
return eventActionId;
}
}
public Hashtable Parameters
{
get
{
Hashtable hParameters = new Hashtable();
string[] paramCouples = parameter.Split('&');
for (int i = 0; i < paramCouples.Length; i++)
{
string[] keyValue = paramCouples[i].Split('=');
hParameters.Add(keyValue[0], keyValue[1]);
}
return hParameters;
}
}
public Event()
{
}
then inside a webservice I have the following code :
[WebMethod]
public Event SetGameLive(int gameId, bool isLiveGame)
{
Event oEvent;
SqlConnection connection = ConnectionManager.GetBookieConnection();
try
{
connection.Open();
SelectedGamePersistent selectedGame = new SelectedGamePersistent(gameId,
connection);
selectedGame.IsLive = isLiveGame;
selectedGame.UpdateSelectedGame(connection, out oEvent); // here my
oEvent object is instanciated an returned as an out parameter.
}
catch (Exception ex)
{
oEvent = null;
}
finally
{
connection.Close();
}
return oEvent;
}
When I run the webservice, the Event object is being XML serialized
automatically by the run time and then I did not implement any specific
method in the Event object to manually XML serialize my object.
From what I see in your code, you are serializing the hashtable in a binary
fashion to save it in a file isn't it? But I need an XML serialization.
Then should I serialize my hashtable manually? How? And how can i replace
the default serialization mechanism by my own one if I need to serialize the
object manually?
And on top of all is why Hashtable is not serializable as it implements
ISerializable interface?
best regards,
Francois
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl... The question was "How can I make the Hashtable serializable ", right? This code snaplet is very famous in i-net, however if the answer can not halp you, I'm sorry. Please provide exact situation and what you want to do? If I'm using this code on your structure, it works fine without any exception. So what is the problem? Please help me and others to clarify and help you to solve it. -- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message news:OQ*************@TK2MSFTNGP12.phx.gbl... The problem is that I think your code is not related to my question, I found the same code doing a google search - http://radio.weblogs.com/0111551/sto...erialized.html - and it is not helping me in my situation, then before posting stuff, make sure you answer the question, if you cannot answer, just let a chance
for someone to do it.
Tx
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message news:eO**************@TK2MSFTNGP10.phx.gbl... Posting again. Try not to repost the same message more then once.
Regards, ---------------------------------------
using System;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace ConsoleApplication5
{
[Serializable]
struct name
{
public string forname;
public string familyname;
} [Serializable]
struct address
{
public string street;
public int number;
} class clsDataBlock
{ public static Hashtable NameToAddress = new Hashtable (); [STAThread]
static void Main(string[] args)
{
clsDataBlock db=new clsDataBlock ();
string ans=""; while("x" != ans)
{
System.Console.WriteLine ("1 to enter new");
System.Console.WriteLine ("2 to search");
System.Console.WriteLine ("3 to save (serialize)");
System.Console.WriteLine ("4 to load (deserialize)");
System.Console.WriteLine ("5 to show data");
System.Console.WriteLine ("x to quit");
System.Console.WriteLine ("-----------------------"); ans = System.Console.ReadLine (); switch(ans)
{
case "1":db.AddNew();
break;
case "2":db.Search();
break;
case "3":db.Save();
break;
case "4":db.Load();
break;
case "5":db.Show();
break;
}
}
}
public void AddNew()
{
name nm;
address ad;
string ans;
System.Console.WriteLine ("enter first name (x to exit):");
ans = System.Console.ReadLine();
nm.forname = ans; System.Console.WriteLine ("enter last name (x to exit):");
ans = System.Console.ReadLine();
nm.familyname = ans; System.Console.WriteLine ("enter street name (x to exit):");
ans = System.Console.ReadLine();
ad.street = ans; System.Console.WriteLine ("enter street number (x to
exit):"); ans = System.Console.ReadLine();
ad.number = int.Parse (ans); NameToAddress.Add(nm,ad);
} public void Search()
{
name nm2; string ans2;
System.Console.WriteLine ("enter first name:");
ans2 = System.Console.ReadLine ();
nm2.forname = ans2; System.Console.WriteLine ("enter last name:");
ans2 = System.Console.ReadLine ();
nm2.familyname = ans2; System.Console.WriteLine ("working..."); object sname = NameToAddress[nm2];
if (sname != null)
{
address ad2 = (address)sname;
System.Console.WriteLine(" address: "+ ad2.street + " " + ad2.number );
}
else
System.Console.WriteLine ("no name like that..."); } public void Save()
{
FileStream fs = new FileStream ("Store.dat",FileMode.OpenOrCreate ,FileAccess.Write );
try
{
Hashtable a = new Hashtable();
a = NameToAddress;
BinaryFormatter bf=new BinaryFormatter ();
bf.Serialize (fs,a );
}
finally
{
fs.Close ();
}
}
public void Load()
{
FileStream fs = new FileStream ("Store.dat",FileMode.Open ,FileAccess.Read );
try
{
Hashtable a = new Hashtable();
BinaryFormatter bf=new BinaryFormatter ();
a=(Hashtable)bf.Deserialize (fs);
NameToAddress = a;
}
finally
{
fs.Close ();
}
}
public void Show()
{
name nm3;
address ad3;
foreach (DictionaryEntry entry in NameToAddress )
{
nm3 = (name)entry.Key;
ad3 = (address)entry.Value;
Console.WriteLine ("name= {0} {1}, address= {2} {3}",
nm3.forname,nm3.familyname ,ad3.street ,ad3.number);
}
}
}
} Hope it helps -- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message news:OE**************@TK2MSFTNGP12.phx.gbl... > Hi, > > I have a webservice that I am using and I would like it to return an XML > serialized version of an object. > > the class of the object is defined serializable as the following: > > [Serializable] > public class Event > { > } > > Also it contains 5 properties returning simple data type such as int and > string. But one of them is an Hashtable. When I run my project i got
a run > time exception telling me that : > > System.InvalidOperationException: There was an error reflecting type > 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type > System.Collections.Hashtable is not supported because it implements > IDictionary. > at System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type type) > > Then my question is: > How can I make the Hashtable serializable to make in turn my Event class > serializable? > > Also I am a little bit surprised as in the .Net framework reference
it is > specified that the > Hashtable class implement the serializable interface... Then it is puzzling > me even more > > Thanks a lot, > > Francois > > -- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message news:O9*************@TK2MSFTNGP11.phx.gbl... > 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. > > the class of the object is defined serializable as the following: > > [Serializable] > public class Event > { > } > > Also it contains 5 properties returning simple data type such as int and > string. But one of them is an Hashtable. When I run my project i got
a run > time exception telling me that : > > System.InvalidOperationException: There was an error reflecting type > 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type > System.Collections.Hashtable is not supported because it implements > IDictionary. > at System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type type) > > Then my question is: > How can I make the Hashtable serializable to make in turn my Event class > serializable? > > Also I am a little bit surprised as in the .Net framework reference
it is > specified that the > Hashtable class implement the serializable interface... Then it is puzzling > me even more. > > Thanks a lot, > > Francois > >
OK, Not it's clear, but I have gloomy answer for you.
Q: Why can't I serialize hashtables?
A: The XmlSerializer cannot process classes implementing the IDictionary
interface. This was partly due to schedule constraints and partly due to the
fact that a hashtable does not have a counterpart in the XSD type system.
The only solution is to implement a custom hashtable that does not implement
the IDictionary interface.
The other option (not tested) is to use SoapFormater for binary
serialization.
Hope it helps
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message
news:uC**************@TK2MSFTNGP11.phx.gbl... First of all thanks a lot and here i will go for more details but i am afraid it may be a little bit lenghty.
This is the full definition of my class:
[Serializable] public class Event { private int eventId; private EventTypeId eventTypeId; private EventActionId eventActionId; private string parameter; //private Hashtable hParameters;
public int EventId { get { return eventId; } }
public EventTypeId EventTypeID //EventTypeId is an enum of int type { get { return eventTypeId; } }
public EventActionId EventActionID //EventActionId is an enum of
int type { get { return eventActionId; } }
public Hashtable Parameters { get { Hashtable hParameters = new Hashtable(); string[] paramCouples = parameter.Split('&'); for (int i = 0; i < paramCouples.Length; i++) { string[] keyValue = paramCouples[i].Split('='); hParameters.Add(keyValue[0], keyValue[1]); } return hParameters; } } public Event() { }
then inside a webservice I have the following code :
[WebMethod]
public Event SetGameLive(int gameId, bool isLiveGame)
{
Event oEvent;
SqlConnection connection = ConnectionManager.GetBookieConnection();
try
{
connection.Open();
SelectedGamePersistent selectedGame = new SelectedGamePersistent(gameId, connection);
selectedGame.IsLive = isLiveGame;
selectedGame.UpdateSelectedGame(connection, out oEvent); // here my oEvent object is instanciated an returned as an out parameter.
}
catch (Exception ex)
{
oEvent = null;
}
finally
{
connection.Close();
}
return oEvent;
}
When I run the webservice, the Event object is being XML serialized automatically by the run time and then I did not implement any specific method in the Event object to manually XML serialize my object. From what I see in your code, you are serializing the hashtable in a
binary fashion to save it in a file isn't it? But I need an XML serialization.
Then should I serialize my hashtable manually? How? And how can i replace the default serialization mechanism by my own one if I need to serialize
the object manually?
And on top of all is why Hashtable is not serializable as it implements ISerializable interface?
best regards,
Francois
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message news:OP**************@TK2MSFTNGP09.phx.gbl... The question was "How can I make the Hashtable serializable ", right?
This code snaplet is very famous in i-net, however if the answer can not halp you, I'm sorry. Please provide exact situation and what you want to do? If I'm using this code on your structure, it works fine without any exception. So what is the problem? Please help me and others to clarify and help you to solve it. -- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
"francois" <fr******@bettinghouses.com_NOSPAM> wrote in message news:OQ*************@TK2MSFTNGP12.phx.gbl... The problem is that I think your code is not related to my question, I found the same code doing a google search - http://radio.weblogs.com/0111551/sto...erialized.html - and it is not helping me in my situation, then before posting
stuff, make sure you answer the question, if you cannot answer, just let a chance for someone to do it.
Tx
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message news:eO**************@TK2MSFTNGP10.phx.gbl... > Posting again. Try not to repost the same message more then once. > > Regards, > --------------------------------------- > > using System; > > using System.Collections; > > using System.Runtime.Serialization.Formatters.Binary; > > using System.IO; > > > namespace ConsoleApplication5 > > { > > [Serializable] > > struct name > > { > > public string forname; > > public string familyname; > > } > > > > [Serializable] > > struct address > > { > > public string street; > > public int number; > > } > > > > class clsDataBlock > > { > > > > public static Hashtable NameToAddress = new Hashtable (); > > > > [STAThread] > > static void Main(string[] args) > > { > > clsDataBlock db=new clsDataBlock (); > > string ans=""; > > > > while("x" != ans) > > { > > System.Console.WriteLine ("1 to enter new"); > > System.Console.WriteLine ("2 to search"); > > System.Console.WriteLine ("3 to save (serialize)"); > > System.Console.WriteLine ("4 to load (deserialize)"); > > System.Console.WriteLine ("5 to show data"); > > System.Console.WriteLine ("x to quit"); > > System.Console.WriteLine ("-----------------------"); > > > > ans = System.Console.ReadLine (); > > > > switch(ans) > > { > > case "1":db.AddNew(); > > break; > > case "2":db.Search(); > > break; > > case "3":db.Save(); > > break; > > case "4":db.Load(); > > break; > > case "5":db.Show(); > > break; > > } > > } > > } > > public void AddNew() > > { > > name nm; > > address ad; > > string ans; > > System.Console.WriteLine ("enter first name (x to exit):"); > > ans = System.Console.ReadLine(); > > nm.forname = ans; > > > > System.Console.WriteLine ("enter last name (x to exit):"); > > ans = System.Console.ReadLine(); > > nm.familyname = ans; > > > > System.Console.WriteLine ("enter street name (x to
exit):"); > > ans = System.Console.ReadLine(); > > ad.street = ans; > > > > System.Console.WriteLine ("enter street number (x to exit):"); > > ans = System.Console.ReadLine(); > > ad.number = int.Parse (ans); > > > > NameToAddress.Add(nm,ad); > > } > > > > public void Search() > > { > > name nm2; > > > > string ans2; > > System.Console.WriteLine ("enter first name:"); > > ans2 = System.Console.ReadLine (); > > nm2.forname = ans2; > > > > System.Console.WriteLine ("enter last name:"); > > ans2 = System.Console.ReadLine (); > > nm2.familyname = ans2; > > > > System.Console.WriteLine ("working..."); > > > > object sname = NameToAddress[nm2]; > > if (sname != null) > > { > > address ad2 = (address)sname; > > System.Console.WriteLine(" address: "+ ad2.street + " "
+ > ad2.number ); > > } > > else > > System.Console.WriteLine ("no name like that..."); > > > > } > > > > public void Save() > > { > > FileStream fs = new FileStream ("Store.dat",FileMode.OpenOrCreate > ,FileAccess.Write ); > > try > > { > > Hashtable a = new Hashtable(); > > a = NameToAddress; > > BinaryFormatter bf=new BinaryFormatter (); > > bf.Serialize (fs,a ); > > } > > finally > > { > > fs.Close (); > > } > > > > > > } > > public void Load() > > { > > FileStream fs = new FileStream ("Store.dat",FileMode.Open > ,FileAccess.Read ); > > try > > { > > Hashtable a = new Hashtable(); > > > > > > BinaryFormatter bf=new BinaryFormatter (); > > a=(Hashtable)bf.Deserialize (fs); > > NameToAddress = a; > > } > > finally > > { > > fs.Close (); > > } > > > > > > } > > public void Show() > > { > > name nm3; > > address ad3; > > foreach (DictionaryEntry entry in NameToAddress ) > > { > > nm3 = (name)entry.Key; > > ad3 = (address)entry.Value; > > Console.WriteLine ("name= {0} {1}, address= {2} {3}", > > nm3.forname,nm3.familyname ,ad3.street ,ad3.number); > > } > > } > > } > > } > Hope it helps > -- > Tamir Khason > You want dot.NET? Just ask: > "Please, www.dotnet.us " > > > "francois" <fr******@bettinghouses.com_NOSPAM> wrote in message > news:OE**************@TK2MSFTNGP12.phx.gbl... > > Hi, > > > > I have a webservice that I am using and I would like it to return
an XML > > serialized version of an object. > > > > the class of the object is defined serializable as the following: > > > > [Serializable] > > public class Event > > { > > } > > > > Also it contains 5 properties returning simple data type such as
int and > > string. But one of them is an Hashtable. When I run my project i
got a run > > time exception telling me that : > > > > System.InvalidOperationException: There was an error reflecting
type > > 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type > > System.Collections.Hashtable is not supported because it
implements > > IDictionary. > > at
System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type type) > > > > Then my question is: > > How can I make the Hashtable serializable to make in turn my Event class > > serializable? > > > > Also I am a little bit surprised as in the .Net framework
reference it is > > specified that the > > Hashtable class implement the serializable interface... Then it is > puzzling > > me even more > > > > Thanks a lot, > > > > Francois > > > > > > > > -- > Tamir Khason > You want dot.NET? Just ask: > "Please, www.dotnet.us " > > > "francois" <fr******@bettinghouses.com_NOSPAM> wrote in message > news:O9*************@TK2MSFTNGP11.phx.gbl... > > 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. > > > > the class of the object is defined serializable as the following: > > > > [Serializable] > > public class Event > > { > > } > > > > Also it contains 5 properties returning simple data type such as
int and > > string. But one of them is an Hashtable. When I run my project i
got a run > > time exception telling me that : > > > > System.InvalidOperationException: There was an error reflecting
type > > 'Bos.BizObj.Event'. ---> System.NotSupportedException: The type > > System.Collections.Hashtable is not supported because it
implements > > IDictionary. > > at
System.Xml.Serialization.TypeScope.GetCollectionEl ementType(Type type) > > > > Then my question is: > > How can I make the Hashtable serializable to make in turn my Event class > > serializable? > > > > Also I am a little bit surprised as in the .Net framework
reference it is > > specified that the > > Hashtable class implement the serializable interface... Then it is > puzzling > > me even more. > > > > Thanks a lot, > > > > Francois > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Cederstrom |
last post by:
Hello group! :)
I want to create a config/status object, that will contain a Hashtable. This
object I would like to save through Serialization, but im having some
trouble. My hashtable contain...
|
by: Arjen |
last post by:
Hello,
Can somebody help me a little bit?
I can't get it to work.
Please see my code below... I have placed some comments like "// And whats
next?".
I'm sure that I have to code something...
|
by: Arjen |
last post by:
Hi there,
I have tried to run some samples without succes.
So I have made a new sample. Maybe someone can fix the serialization?
The class "MyProgram" must be saved to an xml file and placed...
|
by: francois |
last post by:
Hi,
I have a webservice that I am using and I would like it to return an XML
serialized version of an object.
the class of the object is defined serializable as the following:
public...
|
by: oDDskOOL |
last post by:
I realized today that the Hashtable.Clone only produces a shallow
copy... that makes me go mad that M$ doesn't even provide a deep copy
ctor for the Hashtable class !
mighty tech ducks might...
|
by: Brian Keating |
last post by:
hi there,
has anyone had success in serializing a 2.0 case sensivite hashtable
ie.
private Hashtable m_itemsById = new Hashtable(
new CaseInsensitiveHashCodeProvider(),
new...
|
by: Wild Wind |
last post by:
Hello,
I've been battling over this problem for
the better part of a day, so I'd appreciate it
if someone could shed some light here.
I have a file which is produced by the custom binary...
|
by: Joe |
last post by:
I've tracked the performance issue down to a single class. This class
derives from CollectionBase and stores a basic value type such as string,
int, double, etc... I also store the type itself...
|
by: Ron M. Newman |
last post by:
Hi,
I have a simple class that has a Hashtable. the hashtable has a couple of
key/value pairs where the key is a string and the value is also a strong.
I have at the top of that class.
...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
| |