Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot convert input parameter to type 'Microsoft.DurableTask.TaskOrchestrationContext' from type 'System.String' #43

Closed
Krusty93 opened this issue Aug 31, 2022 · 2 comments

Comments

@Krusty93
Copy link

Krusty93 commented Aug 31, 2022

I am trying to set durable functions as follow:

using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using Microsoft.DurableTask;

public class QAReportOrchestrationFunction
{
    [Function(nameof(TimerTriggerStart))]
    public static async Task TimerTriggerStart(
        [TimerTrigger("0 6 * * Mon", RunOnStartup = true)] TimerInfo timer,
        [DurableClient] DurableClientContext starter,
        FunctionContext functionContext)
    {
        var orchestrationId = await starter.Client.ScheduleNewOrchestrationInstanceAsync(nameof(RunOrchestrator));
    }

    [Function(nameof(RunOrchestrator))]
    public static async Task<string> RunOrchestrator(
        [OrchestrationTrigger] TaskOrchestrationContext context)
    {
        string result = "";
        result += await context.CallActivityAsync<string>(nameof(SayHello), "Tokyo") + " ";
        result += await context.CallActivityAsync<string>(nameof(SayHello), "London") + " ";
        result += await context.CallActivityAsync<string>(nameof(SayHello), "Seattle");
        return result;
    }

    [Function(nameof(SayHello))]
    public static string SayHello(
        [ActivityTrigger] string name)
    {
        return $"Hello {name}!";
    }
}
internal class Program
{
    public static async Task Main(string[] _)
    {
        var host = new HostBuilder()
            .ConfigureFunctionsWorkerDefaults()
            .Build();

        await host.RunAsync();
    }
}
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="0.4.1-beta" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
  </ItemGroup>

  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>

</Project>
{
  "IsEncrypted": false,
  "Values": {
    "ASPNETCORE_ENVIRONMENT": "Development",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}

However, when the client function tries to invoke the orchestrator function, I get this error:

[2022-08-31T10:42:51.972Z] Executing 'Functions.TimerTriggerStart' (Reason='Timer fired at 2022-08-31T12:42:51.9287484+02:00', Id=2722cf45-75e1-4c74-ba2b-f36733270863)
[2022-08-31T10:42:51.976Z] Trigger Details: UnscheduledInvocationReason: RunOnStartup
[2022-08-31T10:42:53.760Z] Worker process started and initialized.
[2022-08-31T10:42:56.558Z] Host lock lease acquired by instance ID '00000000000000000000000067BD87D1'.
[2022-08-31T10:43:19.964Z] Scheduling new RunOrchestrator orchestration with instance ID '0e90a778968a44d3ab39c924d01bc6c7' and 0 bytes of input data.
[2022-08-31T10:43:20.287Z] Executing 'Functions.RunOrchestrator' (Reason='(null)', Id=e4b48ac1-2255-45fd-9be8-10b7b0fd371e)
[2022-08-31T10:43:21.283Z] Executed 'Functions.TimerTriggerStart' (Succeeded, Id=2722cf45-75e1-4c74-ba2b-f36733270863, Duration=29336ms)
[2022-08-31T10:43:21.342Z] Executed 'Functions.RunOrchestrator' (Failed, Id=e4b48ac1-2255-45fd-9be8-10b7b0fd371e, Duration=1069ms)
[2022-08-31T10:43:21.345Z] System.Private.CoreLib: Exception while executing function: Functions.RunOrchestrator. System.Private.CoreLib: Result: Failure
Exception: Microsoft.Azure.Functions.Worker.FunctionInputConverterException: Error converting 1 input parameters for Function 'RunOrchestrator': Cannot convert input parameter 'context' to type 'Microsoft.DurableTask.TaskOrchestrationContext' from type 'System.String'. Error:System.Text.Json.JsonException: 'C' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
[2022-08-31T10:43:21.345Z]  ---> System.Text.Json.JsonReaderException: 'C' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.

I literally don't get where this string is coming from and what could be its value. This is a brand new project and I'm cleaning Azurite storage at each run. Tried both VS and VS Code

EDIT:
Changing the RunOrchestrator function parameter I can get the string value:

    [Function(nameof(RunOrchestrator))]
    public static async Task<string> RunOrchestrator(
        [OrchestrationTrigger] string context)
    {
        await Task.Delay(190);
        string result = "";
        return result;
    }

context value: CiAxZTZhYjQxMmMyMzc0Zjc5YWM4NzllMzFkNmE3ZDkwYSIaCP///////////wESCwiuqL2YBhCU2Ys5cgAigwEI////////////ARIMCK2ovZgGEOTKvcQDGmgKD1J1bk9yY2hlc3RyYXRvchIAGgcKBSJhYWEiIkoKIDFlNmFiNDEyYzIzNzRmNzlhYzg3OWUzMWQ2YTdkOTBhEiYKJDRlZDA4ZDE4LTg4NjMtNDMyNC05NzBhLWY1MjkwNDQ3YTEyYg==

@kshyju
Copy link
Contributor

kshyju commented Aug 31, 2022

Could you try using the latest preview version(1.7.0-preview2) of the Microsoft.Azure.Functions.Worker.Sdk package?

@Krusty93
Copy link
Author

Krusty93 commented Sep 1, 2022

@kshyju, I confirm that it works with the package version you suggested. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants