msgraph-sdk-dotnet-core
msgraph-sdk-dotnet-core copied to clipboard
Cannot deserialize Microsoft.Graph.ServiceException
Please provide the following (and please check them off the list with [x]) before submitting this issue:
- [x] Expected behavior. Please provide links to the specific Microsoft Graph documentation you used to determine the expected behavior.
- [x] Actual behavior. Provide error codes, stack information, and a Fiddler capture of the request and response (please remove personally identifiable information before posting).
- [x] Steps to reproduce the behavior. Include your code, IDE versions, client library versions, and any other information that might be helpful to understand your scenario.
Expected behavior
Instances of Microsoft.Graph.ServiceException can be deserialized.
Actual behavior
---> DurableTask.Core.Exceptions.TaskFailedExceptionDeserializationException:
Failed to deserialize exception from TaskActivity: {"$type":"Microsoft.Graph.ServiceException, Microsoft.Graph.Core", ...
---> Newtonsoft.Json.JsonSerializationException:
Unable to find a constructor to use for type Microsoft.Graph.ServiceException.
A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute.
Steps to reproduce the behavior
The Durable Task framework serializes the state of tasks, including exceptions. The Microsoft.Graph.ServiceException serializes fine, but does not deserialize as described above.
Items for discussion:
- All the properties of the class have private setters. So deserializing via a default constructor will not initialize them.
- All constructor overloads eventually try to instantiate a HttpResponseHeaders object. Deserialization then throws: Newtonsoft.Json.JsonSerializationException : Cannot create and populate list type System.Net.Http.Headers.HttpResponseHeaders.
I wonder if we can move consumers into a pit of success by setting JsonIgnore on properties other than the Error and attributing the 1st ctor ( ServiceException(Error error, Exception innerException = null) ) as the JsonConstructor?
Closed via #510