c# - Task`1 cannot be serialized for Web Application referencing BCL.Async -


we deployed newly developed pre-compiled service our test domain , received following error:

type 'system.threading.tasks.task`1[domain.infrastructure.contracts.configuration.domainservices]' cannot serialized. consider marking datacontractattribute attribute, , marking of members want serialized datamemberattribute attribute.  if type collection, consider marking collectiondatacontractattribute.  see microsoft .net framework documentation other supported types.  

the server windows 2008r2 running .net 4.0.

there has been few stack overflow questions this, seem referring ctp release of async. apparently must have .net 4.5 installed on server in order use code.

has situation changed @ release of bcl.async nuget package?

i under impression code compiled async compiler , includes bcl libraries nuget had needed run in .net 4 environment.

is still case have upgrade .net runtime on server 4.5?

edit: stack trace provided:

[invaliddatacontractexception: type 'system.threading.tasks.task`1[domain.infrastructure.contracts.configuration.domainservices]' cannot serialized. consider marking datacontractattribute attribute, , marking of members want serialized datamemberattribute attribute.  if type collection, consider marking collectiondatacontractattribute.  see microsoft .net framework documentation other supported types.] system.runtime.serialization.datacontractcriticalhelper.throwinvaliddatacontractexception(string message, type type) +1184850 system.runtime.serialization.datacontractcriticalhelper.createdatacontract(int32 id, runtimetypehandle typehandle, type type) +787 system.runtime.serialization.datacontractcriticalhelper.getdatacontractskipvalidation(int32 id, runtimetypehandle typehandle, type type) +117 system.runtime.serialization.xsddatacontractexporter.getschematypename(type type) +85 system.servicemodel.dispatcher.datacontractserializeroperationformatter.createpartinfo(messagepartdescription part, operationformatstyle style, datacontractserializeroperationbehavior serializerfactory) +48 system.servicemodel.dispatcher.datacontractserializeroperationformatter.createmessageinfo(datacontractformatattribute datacontractformatattribute, messagedescription messagedescription, datacontractserializeroperationbehavior serializerfactory) +708 system.servicemodel.dispatcher.datacontractserializeroperationformatter..ctor(operationdescription description, datacontractformatattribute datacontractformatattribute, datacontractserializeroperationbehavior serializerfactory) +570 system.servicemodel.description.datacontractserializeroperationbehavior.getformatter(operationdescription operation, boolean& formatrequest, boolean& formatreply, boolean isproxy) +308 system.servicemodel.description.datacontractserializeroperationbehavior.system.servicemodel.description.ioperationbehavior.applydispatchbehavior(operationdescription description, dispatchoperation dispatch) +69 system.servicemodel.description.dispatcherbuilder.bindoperations(contractdescription contract, clientruntime proxy, dispatchruntime dispatch) +120 system.servicemodel.description.dispatcherbuilder.initializeservicehost(servicedescription description, servicehostbase servicehost) +4250 system.servicemodel.servicehostbase.initializeruntime() +82 system.servicemodel.servicehostbase.onopen(timespan timeout) +64 system.servicemodel.channels.communicationobject.open(timespan timeout) +789 system.servicemodel.hostingmanager.activateservice(string normalizedvirtualpath) +255 system.servicemodel.hostingmanager.ensureserviceavailable(string normalizedvirtualpath) +1172  [serviceactivationexception: service '/services/binary/endpoint.svc' cannot activated due exception during compilation.  exception message is: type 'system.threading.tasks.task`1[domain.infrastructure.contracts.configuration.domainservices]' cannot serialized. consider marking datacontractattribute attribute, , marking of members want serialized datamemberattribute attribute.  if type collection, consider marking collectiondatacontractattribute.  see microsoft .net framework documentation other supported types..] system.runtime.asyncresult.end(iasyncresult result) +901504 system.servicemodel.activation.hostedhttprequestasyncresult.end(iasyncresult result) +178638 system.web.asynceventexecutionstep.onasynceventcompletion(iasyncresult ar) +107 

okay, i'm going take guess here you're trying expose asynchronous wcf operation returns task<domain.infrastructure.contracts.configuration.domainservices>. while microsoft.bcl.async allow compile code uses tasks, won't provide .net framework 4.5 changes wcf allow use tasks in services.

that being said, can still use asynchronous programming model expose asynchronous method wcf, while still writing code using tpl. so, you'll have wrap method apm begin/end methods. this:

[servicecontractattribute] public interface isampleservice {     [operationcontractattribute]     string samplemethod();      [operationcontractattribute(asyncpattern = true)]     iasyncresult beginsamplemethod(asynccallback callback, object asyncstate);      string endsamplemethod(iasyncresult result); }  public class sampleservice : isampleservice {     // async method needs private wcf doesn't try     // understand return type of task<string>     private async task<string> samplemethodasync()     {         // perform async operation here     }      public string samplemethod()     {         return this.samplemethodasync().result;     }      public iasyncresult beginsamplemethod(asynccallback callback, object asyncstate)     {         var task = this.samplemethodasync();         if (callback != null)         {             task.continuewith(_ => callback(task));         }          return task;     }      public string endsamplemethod(iasyncresult result)     {         return ((task<string>)result).result;     } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -