VS 中的潜在误报警告? "DF0108: Activity function named '{myfunction}' doesn't have an input"

Potential False Positive warning in VS? "DF0108: Activity function named '{myfunction}' doesn't have an input"

我有一个带有 activity 触发器的持久函数,它将一个枚举值作为输入。

这里是从编排器内部调用 activity 触发器。

await context.CallActivityAsync("NotifySolutionStatus", SolutionStatus.Status.Completed);

这里是 activity 触发器签名:

[FunctionName("NotifySolutionStatus")]
public static async Task NotifySolutionStatus(
   [ActivityTrigger] SolutionStatus.Status status,
   [SignalR(HubName = "broadcast")] IAsyncCollector<SignalRMessage> signalRMessages,
   ILogger log)

Visual Studio 2019 返回警告:

Activity function named 'NotifySolutionStatus' doesn't have an input. Pass null for the input parameter

令我感到奇怪的是,activity 触发器工作正常,并且输入值成功传递。此外,对于其他 activity 触发器

的任何其他调用都不会引发此警告

下面的代码似乎没有问题:

using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.SignalRService;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp53
{
    public static class Function1
    {
        public enum Status
        {
            Spring=0,
            Summer=1,
            Autumn=2,
            Winter=3
        }
        [FunctionName("Function1")]
        public static async Task<List<string>> RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            var outputs = new List<string>();

            outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", Function1.Status.Spring));
            outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", Function1.Status.Summer));
            outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", Function1.Status.Autumn));

            return outputs;
        }

        [FunctionName("Function1_Hello")]
        public static string SayHello([ActivityTrigger] Function1.Status name, [SignalR(HubName = "chat")] IAsyncCollector<SignalRMessage> signalRMessages, ILogger log)
        {
            log.LogInformation($"Saying hello to {name}.");
            return $"Hello {name}!";
        }

        [FunctionName("Function1_HttpStart")]
        public static async Task<HttpResponseMessage> HttpStart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            // Function input comes from the request content.
            string instanceId = await starter.StartNewAsync("Function1", null);

            log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

            return starter.CreateCheckStatusResponse(req, instanceId);
        }
    }
}

这是输出:

关于错误或警告:

也许你可以展示你的代码?

最近发现了这一点,解决方案是从参数类型中删除所有命名空间。

所以这会启动分析器

public async Task<ServiceResult<Models.Folder.Item>> Run(
        [ActivityTrigger] Models.Folder.Item item)
    {
        //code
    }

重构为

public async Task<ServiceResult<Models.Folder.Item>> Run(
        [ActivityTrigger] Item item)
    {
        //code
    }

分析员很满意。在我的具体情况下,由于命名空间冲突,我不得不为 Type 设置别名来解决这个问题。

我刚刚与名为 Error DF0108: Activity function 的相同行为作斗争,并找到了一个有趣的解决方案来解决我目前的情况。

编译器似乎检查你输入的内容是否在函数内部使用,但编译器只检查函数代码的第一行。通过使方法调用 blabla.GetInput<ResultObject>() 不是您函数中的第一行代码,可以重现此编译行为。

编译没有问题

public async Task<Response> SendSomethingAsync([ActivityTrigger] IDurableActivityContext context)
        {
            var input = context.GetInput<Input>();
            var correlationId = context.InstanceId;

            // ...
        }

错误 DF0108:Activity 函数

public async Task<Response> SendSomethingAsync([ActivityTrigger] IDurableActivityContext context)
        {
            var correlationId = context.InstanceId;
            var input = context.GetInput<Input>();
            
            // ...
        }