KeyedCollection not serializable with SoapFormatter?

Hi,

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

System.Runtime.Serialization.SerializationException: 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:


public class SoapTests
{

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);
}
}
}


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


public class TestItem
{
string _name;

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

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

Best Regards,

Wiebe Tijsma

1 comment
Comment actions Permalink

My apologies, wrong newsgroup, meant to post on
news.microsoft.com/microsoft.public.dotnet.languages.csharp

Wiebe Tijsma wrote:

Hi,

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

System.Runtime.Serialization.SerializationException: 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:


public class SoapTests
{

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);
}
}
}


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


public class TestItem
{
string _name;

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

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

Best Regards,

Wiebe Tijsma

0

Please sign in to leave a comment.