473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Using generic list with SoapFormatter

I'm trying to use an SoapFormatter with a generic List (List<int>)
(.NET 2.0)
When I use it I get an exception that states that the collections from
Generic-namespace cannot be used with the SoapFormatter.
Why does the SoapFormatter not support generics?

Dec 12 '05 #1
1 7449
I found an answer how to fix it by doing my own serialization. I have
translated it from C++/CLI (C++.NET) into C# and but only tested with
C++.NET (remember the right namespaces!!!!!)

List<int> l;
for (int x=0; x< 10; x++)
l.Add (x);

Serialize:
Stream s = new FileStream("foo.soap", FileMode.Create,
FileAccess.Write, FileShare.None);
SoapFormatter sf = new SoapFormatter();
sf.Serialize(s, l.ToArray() );
s.Close();

Deserialize:
Stream s = new FileStream("foo.soap", FileMode.Open, FileAccess.Read,
FileShare.None);
SoapFormatter sf = new SoapFormatter();
int[] tmp = (int[])(sf.Deserialize(s));
l = new List<int>((System::Collections::Generic::IEnumerab le<int>)
tmp);
s->Close();

A generic List<int> inside an object:
[Serializable]
public class Test: ISerializable
{
public List<int> l_ = new List<int>;
public Test() {
for (int i = 9; i>= 0; --i)
{
l_.Add(i);
}
}

internal Test(SerializationInfo si, StreamingContext context) {
int[] tmp = int[](si.GetValue("l_", typeof(int[]) ));
l_ = new
List<int>((System::Collections::Generic::IEnumerab le<int>) tmp);
}
public void GetObjectData( SerializationInfo info, StreamingContext
/*context*/ )
{
//SerializationInfo - essentially a property bag
info.AddValue("l_", l_.ToArray(), typeof(int[]));
Type t = this.GetType();
info.AddValue("TypeObj", t);
}
}

Dec 12 '05 #2

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

Similar topics

2
by: Wiktor Zychla | last post by:
After signing all my assemblies with strong keys, I've found that the application refuses to deserialize any SOAP serialized data. The message says: Parse error, no assembly associated with the...
2
by: Jarda | last post by:
Hi all, i'm looking for some performance comparison some charts. I have read the xmlserializer is better, more flexible and faster (analyzing data types in constructor), but there are some...
1
by: Jim S | last post by:
I have an application where I have to make a tree of objects. To do this, I have my own node class. At certain points in the application, I need to save data. I am having a problem with the...
2
by: Phillip Galey | last post by:
I have an object called Place which contains only string properties and has the <Serializable()> flag before the class name declaration. I also have a collection object called Places, which is...
0
by: seckley | last post by:
Hi i'm working on a project for school, i have created a serializable class that handles a person's name and address. i am using the collection class to handle the data. i then have to use a...
0
by: JackRazz | last post by:
I'm trying to serialize a collection to a file stream by serializing each object individually. The code below works fine with the BinaryFormatter, but the SoapFormatter reads the first object and...
0
by: GrandpaB | last post by:
I have an error that I have not been able to find. Any insight you can offer would be most appreciated. I believe that the problem is associated with the SoapFormatter. The application allows...
1
by: Joachim | last post by:
Can you import namespaces into an ASP .NET 2005 web site project C# file? For instance, when I run using System.Collections.Generic; public partial class _Default : System.Web.UI.Page, IMainView...
0
by: crazyone | last post by:
I've got a gaming framework i'm building and i want to save myself the trouble of reading and writting the complete game data to a custom file and load/save it to an XML file but i'm getting...
0
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
0
BarryA
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...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...

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.