Error deserializing the object DateTime content in Azure Function

Prashant S Miraje 0 Reputation points
2025-06-16T12:34:11.0833333+00:00

Hi Team,

I have been working on Azure function , where i have been reading Json Data(Dynamics CRM Json Data) in ServiceBusTrigger .

I am reading Json Data using Remote Execution Context property however i am getting error while desterilizing content (Error - There was an error deserializing the object of type Microsoft.Xrm.Sdk.RemoteExecutionContext. DateTime content '2025-06-02T05:57:00.679Z' does not start with '/Date(' and end with ')/' as required for JSON).

Can you pls assist me how to read Input Parameter Collection attributes data in Azure ?

Following JSON data i am passing to above Service Bus Trigger

{ "BusinessUnitId": "b1280466-ce31-f011-8c4f-00224819e439", "CorrelationId": "65e45886-f731-4786-aae7-f4401e5fb4fb", "Depth": 1, "InitiatingUserAgent": "", "InitiatingUserAzureActiveDirectoryObjectId": "316ec54e-704a-401b-8ba7-5ebabb5c8be6", "InitiatingUserId": "b12f0466-ce31-f011-8c4f-00224819e439", "InputParameters": [ { "key": "Target", "value": { "__type": "Entity:http://schemas.microsoft.com/xrm/2011/Contracts", "Attributes": [ { "key": "modifiedby", "value": { "__type": "EntityReference:http://schemas.microsoft.com/xrm/2011/Contracts", "Id": "b12f0466-ce31-f011-8c4f-00224819e439", "KeyAttributes": [], "LogicalName": "systemuser", "Name": null, "RowVersion": null } }, { "key": "name", "value": "Prrrash-Mir-Lo" }, { "key": "accountid", "value": "a127b3f4-9734-f011-8c4d-6045bd599559" }, { "key": "modifiedon", "value": "2025-06-02T05:56:59Z" }, { "key": "sic", "value": "SSC" }, { "key": "customertypecode", "value": { "__type": "OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts", "Value": 1 } }, { "key": "telephone1", "value": "555-01521" }, { "key": "industrycode", "value": { "__type": "OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts", "Value": 1 } }, { "key": "modifiedonbehalfby", "value": null } ], "EntityState": null, "FormattedValues": [], "Id": "a127b3f4-9734-f011-8c4d-6045bd599559", "KeyAttributes": [], "LogicalName": "account", "RelatedEntities": [], "RowVersion": null } } ], "IsExecutingOffline": false, "IsInTransaction": true, "IsOfflinePlayback": false, "IsolationMode": 1, "MessageName": "Update", "Mode": 0, "OperationCreatedOn": "2025-06-02T05:57:00.679Z", "OperationId": "ce5a00fa-bdcf-4d5e-8588-a4c4ffe9fbf9", "OrganizationId": "3dba6bb0-8734-f011-9a43-002248ed6f8d", "OrganizationName": "unq3dba6bb08734f0119a43002248ed6", "OutputParameters": [], "OwningExtension": { "Id": "4a27636c-aa3b-f011-8c4e-000d3a858f12", "KeyAttributes": [], "LogicalName": "sdkmessageprocessingstep", "Name": "BridgeWebhook: Update of account", "RowVersion": null }, "ParentContext": { "BusinessUnitId": "b1280466-ce31-f011-8c4f-00224819e439", "CorrelationId": "65e45886-f731-4786-aae7-f4401e5fb4fb", "Depth": 1, "InitiatingUserAgent": "", "InitiatingUserAzureActiveDirectoryObjectId": "316ec54e-704a-401b-8ba7-5ebabb5c8be6", "InitiatingUserId": "b12f0466-ce31-f011-8c4f-00224819e439", "InputParameters": [ { "key": "Target", "value": { "__type": "Entity:http://schemas.microsoft.com/xrm/2011/Contracts", "Attributes": [ { "key": "sic", "value": "SSC" }, { "key": "industrycode", "value": { "__type": "OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts", "Value": 1 } }, { "key": "customertypecode", "value": { "__type": "OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts", "Value": 1 } }, { "key": "telephone1", "value": "555-01521" }, { "key": "name", "value": "Prrrash-Mir-Lo" }, { "key": "accountid", "value": "a127b3f4-9734-f011-8c4d-6045bd599559" } ], "EntityState": null, "FormattedValues": [], "Id": "a127b3f4-9734-f011-8c4d-6045bd599559", "KeyAttributes": [], "LogicalName": "account", "RelatedEntities": [], "RowVersion": null } }, { "key": "x-ms-app-name", "value": "msdynce_saleshub" }, { "key": "SuppressDuplicateDetection", "value": false } ], "IsExecutingOffline": false, "IsInTransaction": true, "IsOfflinePlayback": false, "IsolationMode": 1, "MessageName": "Update", "Mode": 0, "OperationCreatedOn": "2025-06-02T05:56:59.397Z", "OperationId": "ce5a00fa-bdcf-4d5e-8588-a4c4ffe9fbf9", "OrganizationId": "3dba6bb0-8734-f011-9a43-002248ed6f8d", "OrganizationName": "unq3dba6bb08734f0119a43002248ed6", "OutputParameters": [], "OwningExtension": { "Id": "63cdbb1b-ea3e-db11-86a7-000a3a5473e8", "KeyAttributes": [], "LogicalName": "sdkmessageprocessingstep", "Name": "ObjectModel Implementation", "RowVersion": null }, "ParentContext": null, "PostEntityImages": [], "PreEntityImages": [], "PrimaryEntityId": "a127b3f4-9734-f011-8c4d-6045bd599559", "PrimaryEntityName": "account", "RequestId": "ce5a00fa-bdcf-4d5e-8588-a4c4ffe9fbf9", "SecondaryEntityName": "none", "SharedVariables": [ { "key": "IsAutoTransact", "value": true }, { "key": "AcceptLang", "value": "en-US,en;q=0.9" }, { "key": "x-ms-app-name", "value": "msdynce_saleshub" }, { "key": "ChangedEntityTypes", "value": [ { "__type": "KeyValuePairOfstringstring:#System.Collections.Generic", "key": "lead", "value": "Update" }, { "__type": "KeyValuePairOfstringstring:#System.Collections.Generic", "key": "postfollow", "value": "Update" }, { "__type": "UserAzureActiveDirectoryObjectId": "316ec54e-704a-401b-8ba7-5ebabb5c8be6", "UserId": "b12f0466-ce31-f011-8c4f-00224819e439" }, "PostEntityImages": [], "PreEntityImages": [], "PrimaryEntityId": "a127b3f4-9734-f011-8c4d-6045bd599559", "PrimaryEntityName": "account", "RequestId": "ce5a00fa-bdcf-4d5e-8588-a4c4ffe9fbf9", "SecondaryEntityName": "none", "SharedVariables": [ { "key": "IsAutoTransact", "value": true }, { "key": "AcceptLang", "value": "en-US,en;q=0.9" }, { "key": "x-ms-app-name", "value": "msdynce_saleshub" } ], "Stage": 40, "UserAzureActiveDirectoryObjectId": "316ec54e-704a-401b-8ba7-5ebabb5c8be6", "UserId": "b12f0466-ce31-f011-8c4f-00224819e439" }

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RithwikBojja 3,055 Reputation points Microsoft External Staff Moderator
    2025-06-17T04:21:38.62+00:00

    Hi @Prashant S Miraje,

    Initially after using the code provided, I have also got similar error:

    Json Used:

    {
      "BusinessUnitId": "b1280Rithwik819e439",
      "CorrelationId": "65e4588Chotub4fb",
      "Depth": 1,
      "InitiatingUserId": "b12f046Bojjae439",
      "MessageName": "Update",
      "Mode": 0,
      "OperationCreatedOn": "2025-06-02T05:57:00.679Z",
      "OrganizationId": "3dba6bbValueed6f8d",
      "PrimaryEntityId": "a127b3f4Emod599559",
      "InputParameters": [
        {
          "key": "Target",
          "value": {
            "__type": "Entity:http://schemas.microsoft.com/xrm/2011/Contracts",
            "Attributes": [
              {
                "key": "name",
                "value": "Contoso Inc."
              },
              {
                "key": "modifiedon",
                "value": "2025-06-02T05:56:59Z"
              }
            ],
            "Id": "a127basala99559",
            "LogicalName": "account"
          }
        }
      ]
    }
    

    Error:

    enter image description here

    The Newtonsoft.Json serializer correctly handles standard ISO 8601 date formats (like "2025-06-02T05:57:00.679Z"), whereas the older WCF-style serializer is much stricter — it only accepts dates in the legacy \/Date(milliseconds)\/ format (e.g., "\/Date(1717307820679)\/"), and cannot parse ISO 8601 strings.

    Then tried to change to below code which works:

    function.cs:

    using Newtonsoft.Json;
    using Microsoft.Azure.Functions.Worker;
    using Azure.Messaging.ServiceBus;
    using Microsoft.Extensions.Logging;
    using System.Threading.Tasks;
    using Microsoft.Xrm.Sdk;
    
    public class Function1
    {
        private readonly ILogger chlg;
    
        public Function1(ILogger<Function1> lg)
        {
            chlg = lg;
        }
    
        [Function(nameof(Function1))]
        public async Task Run(
            [ServiceBusTrigger("myqueue", Connection = "rithcon")] ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions)
        {
            var json = message.Body.ToString();
            chlg.LogInformation("Raw JSON received: {json}", json);
            var rithexecntxt = JsonConvert.DeserializeObject<RemoteExecutionContext>(json);
            chlg.LogInformation("Deserialized CorrelationId: {id}", rithexecntxt.CorrelationId);
            if (rithexecntxt.SharedVariables != null)
            {
                foreach (var kvp in rithexecntxt.SharedVariables)
                {
                    if (kvp.Value is DateTime dt)
                    {
                        chlg.LogInformation("SharedVariable {key} has DateTime value: {value}", kvp.Key, dt.ToString("o"));
                    }
                }
            }
            if (rithexecntxt.OperationCreatedOn != DateTime.MinValue)
            {
                chlg.LogInformation("Rithwik the OperationCreatedOn is {timestamp}", rithexecntxt.OperationCreatedOn.ToString("o"));
            }
            await messageActions.CompleteMessageAsync(message);
        }
    }
    

    csproj:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <OutputType>Exe</OutputType>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
      <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.22.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
        <PackageReference Include="Microsoft.Xrm.Sdk.2015" Version="7.1.0.1085" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
      </ItemGroup>
      <ItemGroup>
        <None Update="host.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
      </ItemGroup>
      <ItemGroup>
        <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
      </ItemGroup>
    </Project>
    

    Output:

    enter image description here


    If this answer was helpful, please click "Accept the answer" and mark Yes, as this can help other community members.

    enter image description here

    If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.