在序列化/反序列化时出现DataContract属性和第三方库的问题 [英] Problem with DataContract attribute and 3rd party library in serializing/deserializing

查看:124
本文介绍了在序列化/反序列化时出现DataContract属性和第三方库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在我的MVC应用程序中使用第三方插件。

我正在使用1个Class.cs文件和5个.dll。



现在在我的WCF服务中我有一个IService(接口),在我的.svc.cs文件中我正在使用IService中定义的[操作合同]。

我在Colleps中使用了很少的3个参数来访问Class.cs中的方法



现在在尝试浏览WCF服务时它会给出以下错误:



类型''Microsoft.TeamFoundation.Client.TfsTeamProjectCollection''无法序列化。请考虑使用DataContractAttribute属性对其进行标记,并使用DataMemberAttribute属性标记要序列化的所有成员。如果类型是集合,请考虑使用CollectionDataContractAttribute对其进行标记。有关其他支持的类型,请参阅Microsoft .NET Framework文档。





任何建议,PLZ帮助。

Hi,
I am using a 3rd Party plugin in my MVC Application.
For which i am using 1 Class.cs file & 5 .dlls.

Now in my WCF service i have a IService (Interface) and in my .svc.cs file i am using the [operation contract] defined in the IService .
I have few 3 paratemeters used in the contaract to access the method in Class.cs

Now while trying to browse the WCF service it gives following Error:

Type ''Microsoft.TeamFoundation.Client.TfsTeamProjectCollection'' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.


Any suggestion , PLZ help.

推荐答案

如果您无法访问第三方库,并且他们不使用数据合同,则无法使这些库符合要求。没运气。想想这些第三方对你的工作的有用性。



所有你能做的就是将你需要的所有第三方类型包装到你自己的类型中使用数据合同。但这是一项非常繁琐的工作,其结果对维护非常不利。想一想:你必须重现所有你必须从头开始序列化,因为你不能用作数据成员 [DataMember] 任何第三方类型。您必须开发并行数据类型,并在序列化之前和序列化之后将它们转换为第3方类型(请参阅属性 OnDeserializedAttribute OnDeserializingAttribute OnSerializedAttribute OnSerializingAttribute )。



你可以以某种方式自动化和合理化这种不愉快的工作,发明一些通用的技巧来减轻负担,但你无法避免它。是,我确定。使用没有源代码的第3方库是一个非常值得怀疑的事情。



-SA
If you cannot access to your 3rd-party libraries, and they don''t use Data Contract, you cannot make those library to comply. No luck. Think about usefulness of these 3-rd parties for your work.

All you can do is to wrap all 3-rd party types you need into your own types which use Data Contract. But this is very tedious work, and the result of it will be very bad for maintenance. Think about it: you will have to reproduce all you have to serialize from scratch, as you cannot use as data members [DataMember] any of the 3-rd party types. You will have to develop parallel data types and convert them from and to 3-rd party types before serialization and after serialization (see the attributes OnDeserializedAttribute, OnDeserializingAttribute, OnSerializedAttribute and OnSerializingAttribute).

You can somehow automate and rationalize this unpleasant work, invent some universal tricks to alleviate the burden, but you cannot avoid it. Yes, I''m sure. Using 3-rd party libraries without source code is a very questionable thing.

—SA


这篇关于在序列化/反序列化时出现DataContract属性和第三方库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆