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

花了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
posted @ 2020-02-23 20:46  溪水云天  阅读(368)  评论(0编辑  收藏  举报