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:
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:
If this answer was helpful, please click "Accept the answer" and mark Yes
, as this can help other community members.
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.