数组列表到内存流C# [英] arraylist to memorystream c#
问题描述
Hiii全部...
我之前曾问过这个问题,但没有得到再次询问的答案...
我有一个用户定义数据类型的arraylist ...
我需要通过局域网发送它.
我正在使用WCF进行通信,我知道我必须将arraylist转换为memorystream才能发送数据...
我尝试过这种方法
收合|复制代码
Hiii all...
I have asked that question before but didnt get the answer that y m asking that again...
I have an arraylist with user define data type...
and i need to send it trough LAN.
I am using WCF for communication and I know I have to convert arraylist to memorystream to send data...
I hve tried this method
Collapse | Copy Code
ArrayList history = ie.getHistory();
BinaryFormatter f = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
f.Serialize(ms, history);
但由于用户定义数据类型,我给出了错误...
but I gives error because of user define data type...
"Type 'UrlHistoryLibrary.STATURL' in Assembly 'UrlHistoryLibrary, Version=1.0.4146.25771, Culture=neutral, PublicKeyToken=null' is not marked as serializable."
帮助
感谢
help
thanks
推荐答案
那是因为STATURL
没有标记为可序列化,如异常所示.您必须将SerializableAttribute
添加到您的类型中.例如
That''s becauseSTATURL
is not marked serializable, as the exception says. You have to add theSerializableAttribute
to your type. E.g.
[Serializable]
public class MyClass
{
}
有关.NET中序列化的更多信息,请参见
序列化 [ .NET Framework中的对象序列化 [
For more information on serialization in .NET see
Serialization[^]
Object Serialization in the .NET Framework[^]
这篇关于数组列表到内存流C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!