使用带有额外方法的预编译 Azure 函数时出错

Error when using a precompiled Azure Function with extra methods

我创建了一个非常简单的预编译函数(从生成的工具复制代码):

public class Foo
    {
        public static async Task<HttpResponseMessage> Run(HttpRequestMessage req)
        {
            //log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");

            // parse query parameter
            string name = req.GetQueryNameValuePairs()
                .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
                .Value;

            // Get request body
            dynamic data = await req.Content.ReadAsAsync<object>();

            // Set name to query string or body data
            name = name ?? data?.name;

            return name == null
                ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
                : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
        }
    }

这个驻留的 dll 被复制到函数的文件夹,并在 function.json 中链接如下:

{
  "scriptFile": "ExternalFunction.dll",
  "entryPoint": "ExternalFunction.Foo.Run",  
  "disabled": false,
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in"
    },
    {
      "name": "res",
      "type": "http",
      "direction": "out"
    }
  ]
}

一切正常。

然后我想做的是添加一个要从 运行 方法调用的私有方法,所以(小步骤)我将其添加到 Foo class:

private static string Test()
{
    return "Hello";
}

这会导致 CLI 工具出现以下错误:

error AF007: A method matching the entry point name provided in configuration ('ExternalFunction.Foo.Run') does not exist. Your function must contain a single public method, a public method named 'Run', or a public method matching the name specified in the 'entryPoint' metadata property. Function compilation error error AF007: A method matching the entry point name provided in configuration ('ExternalFunction.Foo.Run') does not exist. Your function must contain a single public method, a public method named 'Run', or a public method matching the name specified in the 'entryPoint' metadata property.

这是一个非常奇怪的消息,因为肯定添加私有静态方法应该不会影响函数能够找到 function.json 中指定的 public 方法?!

有什么想法吗?

这确实很奇怪。

如果这证明是一个缺陷,我将进行重现并打开一个问题来解决问题(我将更新问题或我的调查结果),但与此同时,你应该能够在不同的 class(静态或其他)中创建这些方法并在 class.

上调用该方法