Hi All,
I want to serialize a .NET object and deserialize a JSON object in a custom workflow in Dynamics CRM.
To serialise, I use the following code.
string serializedString = ""; using (var memorystream = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(object)); serializer.WriteObject(memorystream, objectToSerialize); serializedString = Encoding.UTF8.GetString(memorystream.ToArray()); } return serializedString;
The code below is used for deserializing.
T deserializedResult; using (var memorystream = new MemoryStream(Encoding.UTF8.GetBytes(objectToDeserialise))) { var deserializer = new DataContractJsonSerializer(typeof(T)); deserializedResult = (T)deserializer.ReadObject(memorystream); } return deserializedResult;
When I run the custom workflow, it is showing the following error.
Unexpected exception from plug-in (Execute): CustomWorkflow: System.Runtime.Serialization.SerializationException: Expecting element 'root' from namespace ''.. Encountered 'None' with name '', namespace ''.
Please guide me to solve this issue.
Any help is appreciated.
*This post is locked for comments