Azure / durabletask

Durable Task Framework allows users to write long running persistent workflows in C# using the async/await capabilities.
Apache License 2.0
1.51k stars 290 forks source link

Unable to find a constructor to use for type System.DirectoryServices.SearchResult. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. #1002

Closed DSBloom closed 11 months ago

DSBloom commented 11 months ago

I have a TaskActivity that returns an object of type MySearchResult, that in turn has a property of type List<System.DirectoryServices.SearchResult>. The problem is that SearchResult doesn't have a public parameterless constructor, and so Newtonsoft fails to serialize it.

The following code throws a Newtonsoft exception:

   var gatherResults =new List<MySearchResult>();
   Task<MySearchResult> getusersTask = context.ScheduleTask<MySearchResult>(typeof(GetADObjectsTask), ADObjectType.User);
   gatherResults.Add(await getusersTask);

How can I work around this issue?

jviau commented 11 months ago

This is a general serialization issue not specific to DurableTask. You will need to either:

  1. Add custom JSON converter(s) for your type to Newtonsoft.Json
  2. Create a DTO (data transfer object) which is serializable and converts to/from the type you want.
jviau commented 11 months ago

Closing as this is not Durable specific. See https://www.newtonsoft.com/json for more newtonsoft json information.