Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

Serialize ExecutionContext into JSON

Posted on by 266

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? 

  • Suggested answer
    JandostKhoso Profile Picture
    JandostKhoso 266 on at
    RE: Serialize ExecutionContext into JSON

    Yes, I found a solution. The solution was to write a custom code to handle HttpRequest and not using SDK methods. In this way, I was able to send a request and wait for the response synchronously. It is cumbersome but that was the only way I found it working.

  • Wauters Profile Picture
    Wauters 90 on at
    RE: Serialize ExecutionContext into JSON

    We are facing the same challenge. Were you able to resolve the issue?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans