首页 > Web开发 > 详细

.net 4 调用WCF时报错 Type 'System.Threading.Tasks.Task`1[]' cannot be serialized

时间:2020-02-23 22:25:10      阅读:111      评论:0      收藏:0      [点我收藏+]

花了2个小时,终于解决了

参照https://www.cnblogs.com/boywujch/p/1a92652ed40f8a6182339e6469b72028.html

 

开发环境  win10   vs2019 .net4.0

 

运行环境  win7  .net4.0

报错

Type ‘System.Threading.Tasks.Task`1[XXXResponse]‘ 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.

 

原因  Visual Studio 2012以上版本的svcutil默认情况下会生成XXXAsync的调用方法。类似System.Threading.Tasks.Task<T>。但是在运行环境,.Net4.0不支持Task<T>

解决方案

  1. 关闭生成异步方法

    1. svcutil /syncOnly

.net 4 调用WCF时报错 Type 'System.Threading.Tasks.Task`1[]' cannot be serialized

原文:https://www.cnblogs.com/Mblog/p/12354166.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!