Hello
I am trying to serialize Execution Context of a plugin into JSON. However, I get exceptions while conversion.
I tried JsonConvert with the following code:
JsonConvert . SerializeObject ( context , Formatting . Indented , new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore } );
and I get the below exception:
at Contoso.ContosoOnCreate.<GetResponseFromDynDemoProc>d__1.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine) at Contoso.ContosoOnCreate.GetResponseFromDynDemoProc(IPluginExecutionContext context, ITracingService service) at Contoso.ContosoOnCreate.Microsoft.Xrm.Sdk.IPlugin.Execute(IServiceProvider serviceProvider)
When I try the below code:
using ( MemoryStream memoryStream = new MemoryStream ( ) ) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(IPluginExecutionContext)); serializer . WriteObject ( memoryStream , context ); string response = Encoding . Default . GetString ( memoryStream . ToArray ( ) ); }
However in this case, the code is not executed after WriteObject method. I see it returns from the method.
Any idea about Serializing Execution Context in Json?