没有找到类型定义的串行:System.Management.Automation.PSObject在protobuf网 [英] No serializer defined for type: System.Management.Automation.PSObject in Protobuf-net
问题描述
这是我班
[ProtoContract]
internal class Powershellresults
{
internal Powershellresults()
{
}
[ProtoMember(1)]
public Collection<PSObject> PsObjects { get; set; }
[ProtoMember(2)]
public string Script { get; set; }
[ProtoMember(3)]
public string Viewname { get; set; }
}
但我没有得到任何类型定义的串行:System.Management.Automation。 PSObject
当我尝试序列化
but i get No serializer defined for type: System.Management.Automation.PSObject when i try to serialize it
private byte[] SerializeResults(Powershellresults obj)
{
byte[] data;
using (var ms = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(ms, obj);
data = ms.ToArray(); ;
}
return data;
}
PsObject是System.Management.Automation的一部分
PsObject is part of System.Management.Automation
我能解决这个问题,实际上序列化这个集合
Can i get around this and actually serialize this collection?
更新:通过添加到我的序列化方法
UPDATE: by adding to my serialization method
RuntimeTypeModel.Default.Add(typeof(PSObject), true);
我可以得到它serialize-,但它失去了大部分的领域,一旦系列化
如何我能得到它克隆原来的对象,因此它保持它的所有字段和属性的?
I can get it to serialize- but it loses most of it's fields once serialized how do i get it to "clone" the original object so it keeps all of its fields and properties?
修改
我想它了!
我心想这Powershell的必须是能够序列化它的对象,因为你可以查询远程计算机 - 这将是怎么回事能够发送机之间PSObject - 它呢! (呜呼!!!!)
I figured it out! I thought to myself that Powershell had to be able to serialize it's objects, because you can poll remote machines - how else would it be able to send the PSObject between machines - which it does! (woohoo!!!!)
好吧,我发现,这说明了一篇文章,发现我的关键字的 System.Management.Automation.PSSerializer
Well, i found an article that described this, and found my keyword System.Management.Automation.PSSerializer
Collection<PSObject> PSCol = Powershell.Invoke();
string SerializedCollection = PSSerializer.Serialize(PSCol);
//序列化XML做的!
//serialization to XML done!
然后使用序列化protobuf网或什么都...
then Serialize the string using Protobuf-net or what ever...
反序列化是一个有点尴尬,但相当直截了当
反序列化使用字符串:
使用的Protobuf反序列化的字符串,然后...
Deserialization is a bit awkward but pretty straight forward for deserialization use: Use Protobuf to deserialize the string and then...
PSObject obj = PSSerializer.Deserialize(DeserializedString) as PSObject;
Collection<PSObject> DeserializedCollection = new Collection<PSObject>(((ArrayList)obj.ImmediateBaseObject).Cast<PSObject>().ToArray());
和多数民众赞成它..
and thats it..
推荐答案
我想它了!
我心想这Powershell的必须是能够序列化它的对象,因为你可以查询远程计算机 - 这将是怎么回事能够发送机之间PSObject - 它呢! (呜呼!!!!)
I figured it out! I thought to myself that Powershell had to be able to serialize it's objects, because you can poll remote machines - how else would it be able to send the PSObject between machines - which it does! (woohoo!!!!)
好吧,我发现,这说明了一篇文章,发现我的关键字的 System.Management.Automation.PSSerializer
Well, i found an article that described this, and found my keyword System.Management.Automation.PSSerializer
Collection<PSObject> PSCol = Powershell.Invoke();
string SerializedCollection = PSSerializer.Serialize(PSCol);
//序列化XML做的!
//serialization to XML done!
然后使用序列化protobuf网或什么都...
then Serialize the string using Protobuf-net or what ever...
反序列化是一个有点尴尬,但相当直截了当
反序列化使用字符串:
使用的Protobuf反序列化的字符串,然后...
Deserialization is a bit awkward but pretty straight forward for deserialization use: Use Protobuf to deserialize the string and then...
PSObject obj = PSSerializer.Deserialize(DeserializedString) as PSObject;
Collection<PSObject> DeserializedCollection = new Collection<PSObject>(((ArrayList)obj.ImmediateBaseObject).Cast<PSObject>().ToArray());
和多数民众赞成它..
and thats it..
这篇关于没有找到类型定义的串行:System.Management.Automation.PSObject在protobuf网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!