CKeene78
CKeene78

Reputation: 21

InvalidCastException: Azure Durable Functions Error

Locally testing Azure Durable Functions with VSCode + JavaScript. Able to successfully trigger the HTTP triggered Orchestration Client and can even see the request headers + body no problem. However, I receive the following error when attempting to trigger the Orchestrator:

Unable to cast object of type 'Microsoft.Azure.WebJobs.DurableOrchestrationContext' to type 'System.String'

I don't understand why DurableOrchestrationContext is trying to be turned into a string. Code calling the Orchestrator:

context.bindings.patient = [{
    FunctionName: "OrchestratorJS",
    Input: req,
    InstanceId: id
}];

Notes: - I tried sending just a string as the Input, but to no effect. - I have successfully created Durable Functions for a different project which makes this even more frustrating.

Upvotes: 1

Views: 1943

Answers (1)

Katy Shimizu
Katy Shimizu

Reputation: 1111

The Functions runtime is trying to cast DurableOrchestrationContext to a string because of how languages are handled in Functions v2. Unlike v1, v2 runs JavaScript functions through a Node language worker hosted in a different process from the runtime host. The language worker and the host communicate via gRPC protocol. When a function is called, the runtime host must pass bound parameter information to the function over gRPC. Parameters bound to complex objects, like DurableOrchestrationContext, must be serialized to JSON strings, passed via gRPC, and finally rehydrated for a function to consume them.

We introduced DurableOrchestrationContext to string conversion in the 1.4.0 release. Could you try updating to the latest version of the extension (1.5.0) and trying your function again?

Upvotes: 1

Related Questions