472,993 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

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 3952
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). ...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.