Azure / azure-functions-durable-extension

Durable Task Framework extension for Azure Functions
MIT License
715 stars 271 forks source link

Getting Error When Http Trigger Starts Durable Function #1028

Open Ben52 opened 5 years ago

Ben52 commented 5 years ago

Description

Running any Durable function with an HTTP Trigger, when hitting the endpoint, I get an error in the console System.Collections.Immutable: This operation cannot be performed on a default instance of ImmutableArray<T>. Consider initializing the array, or checking the ImmutableArray<T>.IsDefault property.

The Http response is the Check Status Response Object, but it remains running, and doesn't complete.

Expected behavior

I would expect to not get an error in the console, and have the function eventually complete

Actual behavior

An error is occurs, and the Durable function does not run.

App Details

Durable Functions 2.0

MacOs Catalina

Screenshots

image

dc799 commented 5 years ago

@Ben52 could you share what your starter function looks like?

Ben52 commented 5 years ago

Here's the function I have in my app, but I get the same error when I run a simple durable function with no business logic.

        [FunctionName("Ocr_HttpStart")]
        public async Task<HttpResponseMessage> HttpStart(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "ocr")]
            HttpRequestMessage req,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            var query = System.Web.HttpUtility.ParseQueryString(req.RequestUri.Query);
            var getTextAs = query.Get("getTextAs") ?? "fullText";

            byte[] bytes = null;
            switch (req.Content.Headers.ContentType.MediaType)
            {
                case "application/octet-stream":
                    bytes = await req.Content.ReadAsByteArrayAsync();
                    break;
                case "text/plain":
                    bytes = Convert.FromBase64String(await req.Content.ReadAsStringAsync());
                    break;
                case "application/json":
                    break;
                default:
                    throw new Exception("unknown content type");
            }

            DocumentLocation documentLocation = null;
            if (req.Content.Headers.ContentType.MediaType == "application/json")
            {
                documentLocation =
                    JsonConvert.DeserializeObject<DocumentLocation>(await req.Content.ReadAsStringAsync());
            }

            if (query.Get("isDocprobeDocument") != null)
            {
                documentLocation = _docprobeDocumentFactory.DocumentLocation(documentLocation);
            }

            var instanceId =
                await starter.StartNewAsync("Ocr", new OrchestrationPayload
                {
                    Bytes = bytes,
                    GetTextAs = getTextAs,
                    DocumentLocation = documentLocation,
                });

            return starter.CreateCheckStatusResponse(req, instanceId);
        }

And here's the Orchestration function:

        [FunctionName("Ocr")]
        public async Task<string> RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context, ILogger logger)
        {
            logger.LogInformation("IN HERE NOW");
            var payload = context.GetInput<OrchestrationPayload>();

            var options = new RetryOptions(TimeSpan.FromSeconds(30), 10);

            return await context.CallActivityWithRetryAsync<string>(nameof(RunOcr), options, payload);
        }

IN HERE NOW never gets logged out. I've also tried in Windows running Parallels on my Mac and get the same error.

Here's the .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netcoreapp2.2</TargetFramework>
        <AzureFunctionsVersion>v2</AzureFunctionsVersion>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.0.0" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.8" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.2" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.30-beta1" />
    </ItemGroup>
    <ItemGroup>
        <None Update="host.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
    </ItemGroup>
    <ItemGroup>
      <_ResolveComReferenceCache Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.csproj.ResolveComReference.cache" />
      <_ResolveComReferenceCache Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.csproj.ResolveComReference.cache" />
      <_ResolveComReferenceCache Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.csproj.ResolveComReference.cache" />
      <_ResolveComReferenceCache Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.csproj.ResolveComReference.cache" />
    </ItemGroup>
    <ItemGroup>
      <IntermediateAssembly Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.dll" />
      <IntermediateAssembly Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.dll" />
      <IntermediateAssembly Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.dll" />
      <IntermediateAssembly Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.dll" />
    </ItemGroup>
    <ItemGroup>
      <_DebugSymbolsIntermediatePath Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.pdb" />
      <_DebugSymbolsIntermediatePath Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.pdb" />
      <_DebugSymbolsIntermediatePath Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.pdb" />
      <_DebugSymbolsIntermediatePath Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.pdb" />
    </ItemGroup>
    <ItemGroup>
      <_DeploymentManifestEntryPoint Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.dll" />
      <_DeploymentManifestEntryPoint Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.dll" />
      <_DeploymentManifestEntryPoint Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.dll" />
      <_DeploymentManifestEntryPoint Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.dll" />
    </ItemGroup>
    <ItemGroup>
      <ApplicationManifest Remove="obj\Debug\netcoreapp2.2\Native.DocProbe.Ocr.manifest" />
      <ApplicationManifest Remove="obj\Debug\netcoreapp2.2\Native.DocProbe.Ocr.manifest" />
      <ApplicationManifest Remove="obj\Debug\netcoreapp2.2\Native.DocProbe.Ocr.manifest" />
      <ApplicationManifest Remove="obj\Debug\netcoreapp2.2\Native.DocProbe.Ocr.manifest" />
    </ItemGroup>
    <ItemGroup>
      <DeployManifest Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.application" />
      <DeployManifest Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.application" />
      <DeployManifest Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.application" />
      <DeployManifest Remove="obj\Debug\netcoreapp2.2\DocProbe.Ocr.application" />
    </ItemGroup>
</Project>
cgillum commented 5 years ago

Which version of the Azure Functions Core Tools are you using? I think it should be logged as part of the debug output.

Also, have you tried using a non-beta version of Microsoft.NET.Sdk.Functions?

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.30-beta1" />
Ben52 commented 5 years ago

I'm using the latest version of functions-core-tools 2.7.1846. I'm getting the same error with Microsoft.NET.Sdk.Functions version 1.0.29

ConnorMcMahon commented 4 years ago

@Ben52, to clarify, is this happening on Windows as well, or just MacOS?

schneiderpat commented 4 years ago

I'm having the exact same issue with the durable functions default project. OS: Windows 1909 Azure Functions Core Tools (3.0.2009 Commit hash: 77395527a4e9c28da8400dcfd1a450f4e0d0c36c) Function Runtime Version: 3.0.12930.0 .NET SDK: 3.1.100

Sample App

Ben52 commented 4 years ago

@schneiderpat I was able to fix this by setting TargetFramework to 3.1

In your issue description above you list .NET SDK: 3.1.100 as your framework, but in your sample app's .csproj you are targeting 3.0 . Try to update that to 3.1 and see if that helps.

schalkvanwyk commented 4 years ago

I had the same error, turns out that I forgot to add the "FunctionName" attribute to the activity function... Took me two days of trying various combinations of code before I figured out what the problem was. Worst possible error message "the activity function '' failed: "This operation cannot be performed on a default instance of ImmutableArray. Consider initializing the array, or checking the ImmutableArray.IsDefault property."".

ghost commented 4 years ago

This seems to be an error that occurs when an activity function has not been found by an orchestrator.

Much like with @schalkvanwyk, I received this error when forgetting to whitelist my function in host.json using the "functions" property.

markheath commented 4 years ago

I just ran into the same error message - had forgotten to add the FunctionName attribute to my orchestrator function. Would be nice if there could be a more intuitive error message.