2012-04-26 16 views
-3

我期待一個COM對象傳遞到我的WCF的服務器,但是不管我怎麼努力我不斷收到以下錯誤:第三方COM對象不能被序列化。即使包裝成一個數據成員

Type 'System.__ComObject' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.

我已經試過ServiceKnownType

[ServiceKnownType(typeof(ComClass))] 

我曾嘗試它包裹

[DataContract] 
public class receivedClass 
{ 
    [DataMember] 
    public ComClass controlClass { get; set; } 
} 

是否有可能使該序列可以被髮送到我的WCF? (我用這一個IPC程序)

哦,這是COM類是第三方產生

+0

@AnonymousDownvoter請讓我知道我可以在這個問題上改進什麼 – 2012-04-26 20:59:14

+1

沒有。考慮將COM對象的狀態提取到一個紀念對象中併發送它。 – Cheeso 2012-04-26 21:05:04

回答

3

一個COM對象基本上就是指向無人值守內存的指針。它不能被.NET無意中序列化。但是,可能會序列化對象的狀態,在WCF服務中構建COM對象的新對象實例,然後恢復狀態。表示自治信息的com對象的屬性可以被序列化並傳遞給服務器。但是,如果對象是任何未被調整的對象(句柄,內存指針等)的包裝器,則可能非常難以保存COM對象的狀態。

相關問題