W
Wiebe Tijsma
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:
[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
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:
[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