I faced this issue when trying to consume a WCF service in Asp.Net.
The full error message that I got is below:
Type ‘System.Threading.Tasks.Task`1[System.String]’ 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
Exact cause I also do not know but is related to.Net framework version.
If you are using svcutil to generate the proxy class from the WCF url, then we need to add one more attribute to it and the error will go.
Here we are using like below:
svcutil /language:cs /out:generatedproxy.cs /config:app.config net.tcp://localhost/Design_Time_Addresses/SLicense/Service1/
Now we need to add the /syncOnly attribute at the end like below:
svcutil /language:cs /out:generatedproxy.cs /config:app.config net.tcp://localhost/Design_Time_Addresses/SLicense/Service1 /syncOnly
The will generate the generatedproxy.cs file. Use this .cs file, the error will not come.