473,466 Members | 3,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

KeyedCollection serialization with SoapFormatter

Hi,

I'm trying to serialize a KeyedCollection with the SoapFormatter,
however I'm getting the exception:

System.Runtime.Serialization.SerializationExceptio n: Soap Serializer
does not support serializing Generic Types :
System.Collections.Generic.GenericEqualityComparer `1[System.String]

I didn't expose any generic types however, so it's internal to the Keyed
Collection. Any alternatives or workarounds to this?

my test case:

[TestFixture()]
public class SoapTests
{
[Test]
public void TestKeyedCollectionSoapSerialization()
{
TestKeyedCollection collection = new TestKeyedCollection();
collection.Add(new TestItem("Test"));
using (FileStream stream = File.OpenWrite("test.soap"))
{
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(stream, collection);
}
}
}

[Serializable()]
public class TestKeyedCollection : KeyedCollection<string,TestItem>
{
protected override string GetKeyForItem(TestItem item)
{
return item.Name;
}
}

[Serializable()]
public class TestItem
{
string _name;

public TestItem(string name)
{
_name = name;
}

public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
}

Best Regards,

Wiebe Tijsma
Dec 15 '06 #1
3 3974
Hi,

The work around is to use a base class that isn't generic, but since there
isn't a non-generic KeyedCollection implementation, AFAIK, you'll have to
create your own using Hashtable.

--
Dave Sexton

"Wiebe Tijsma" <wi*********@CAPITALStijsma.comwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...
Hi,

I'm trying to serialize a KeyedCollection with the SoapFormatter, however
I'm getting the exception:

System.Runtime.Serialization.SerializationExceptio n: Soap Serializer does
not support serializing Generic Types :
System.Collections.Generic.GenericEqualityComparer `1[System.String]

I didn't expose any generic types however, so it's internal to the Keyed
Collection. Any alternatives or workarounds to this?

my test case:

[TestFixture()]
public class SoapTests
{
[Test]
public void TestKeyedCollectionSoapSerialization()
{
TestKeyedCollection collection = new TestKeyedCollection();
collection.Add(new TestItem("Test"));
using (FileStream stream = File.OpenWrite("test.soap"))
{
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(stream, collection);
}
}
}

[Serializable()]
public class TestKeyedCollection : KeyedCollection<string,TestItem>
{
protected override string GetKeyForItem(TestItem item)
{
return item.Name;
}
}

[Serializable()]
public class TestItem
{
string _name;

public TestItem(string name)
{
_name = name;
}

public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
}

Best Regards,

Wiebe Tijsma

Dec 15 '06 #2
Hi Dave,

Thanks, but I thought it wasn't a problem to inherit from a generic
class, as long as it doesn't expose any generic parameters/fields.

Best Regards,

Wiebe Tijsma

Dave Sexton wrote:
Hi,

The work around is to use a base class that isn't generic, but since there
isn't a non-generic KeyedCollection implementation, AFAIK, you'll have to
create your own using Hashtable.
Dec 15 '06 #3
Hi Wiebe,

A generic type may be serialized as long as its generic parameters are
serializable as well:

".NET Development (General) Technical Articles, Generics FAQ: Best Practices
§ How Do I Serialize Generic Types?"
http://msdn2.microsoft.com/en-us/lib...actices_topic7

But as the error you encountered states, the SoapFormatter doesn't support
serialization of generic types:

"Issues When Using Microsoft Visual Studio 2005
§ 2.36 Using generic types with .NET Remoting and SOAP Serialization"
http://msdn2.microsoft.com/en-us/vstudio/aa718685.aspx

There are no workarounds offered by the article I've cited above.

--
Dave Sexton

"Wiebe Tijsma" <wi*********@CAPITALStijsma.comwrote in message
news:ec**************@TK2MSFTNGP06.phx.gbl...
Hi Dave,

Thanks, but I thought it wasn't a problem to inherit from a generic class,
as long as it doesn't expose any generic parameters/fields.

Best Regards,

Wiebe Tijsma

Dave Sexton wrote:
>Hi,

The work around is to use a base class that isn't generic, but since
there isn't a non-generic KeyedCollection implementation, AFAIK, you'll
have to create your own using Hashtable.

Dec 15 '06 #4

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

Similar topics

0
by: Scott James | last post by:
I've found several useful example showing how to populate a treeview control from an XML file. I've also found a couple examples showing how to serialize a treeview control to an XML file using...
3
by: AA | last post by:
Hello I am having problems with a very simple serialization :( I download the schema http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0 and execute the xsd.exe for...
2
by: Oliver Sturm | last post by:
Say I have a data class: class Data { public List<SubData> SubDataList1 { get ... set ... } public List<Subdata> SubDataList2 { get ... set ... } } It's possible that a specific SubData...
5
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...
3
by: Mike Logan | last post by:
We are trying to serialize the Request.ServerVariables collection (NameValueCollection) to an XML formatted string, to insert into a database. The problem we are running into is that most of the...
2
by: Luck | last post by:
Hi, I really need some expert help... please! Basically, I need to serialize a data structure object to a file using SOAP and then load and de-serialize that file in ANOTHER program. When I...
1
by: Dejan | last post by:
Hello! I need to make an ASP.NET XML Web Service serving as an assembly container. Web Service loads the assembly from a given file, and returns that assembly to the caller. Since ASP.NET...
3
by: Marc | last post by:
Hi, I am trying to serialize a data structure -- a list (of custom class) -- in one application, then read it in with another application. My serialize and deserialize subs are in a module that...
2
by: Peter Duniho | last post by:
I've been learning about mechanisms .NET offers to export data. The initial goal is to see what sorts of ways are available to save an application's state (document, internal database, whatever). ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.