"Method overloads are not supported. There are multiple methods with the name." 当 运行 Azure Functions 在 Docker 时
"Method overloads are not supported. There are multiple methods with the name." when running Azure Functions in Docker
我用这个 Dockerfile
对 Docker
执行了一个非常简单的函数应用程序
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace fapp1
{
public static class HttpIngress
{
[FunctionName("Health")]
public static IActionResult Health([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")] HttpRequest req) => new OkObjectResult("OK");
[FunctionName("HttpIngress")]
[return: ServiceBus("%queuename%", Connection = "servicebusconnection")]
public static async Task<string> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req)
=> await new StreamReader(req.Body).ReadToEndAsync();
}
}
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS installer-env
# Build requires 3.1 SDK
COPY --from=mcr.microsoft.com/dotnet/core/sdk:3.1 /usr/share/dotnet /usr/share/dotnet
COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish *.csproj --output /home/site/wwwroot
# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:4-appservice
FROM mcr.microsoft.com/azure-functions/dotnet:4
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
docker run -it --env-file docker.env test
对于 HttpIngress
中的两个函数,我收到此错误:
fail: Host.Startup[0]
Error indexing method 'Health'
Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'Health'
---> System.InvalidOperationException: Method overloads are not supported. There are multiple methods with the name 'fapp1.HttpIngress.Health'.
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndex.Add(IFunctionDefinition function, FunctionDescriptor descriptor, MethodInfo method) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndex.cs:line 30
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsyncCore(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 349
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 149
--- End of inner exception stack trace ---
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 157
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexTypeAsync(Type type, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 85
fail: Function.Health[0]
Microsoft.Azure.WebJobs.Host: Error indexing method 'Health'. Microsoft.Azure.WebJobs.Host: Method overloads are not supported. There are multiple methods with the name 'fapp1.HttpIngress.Health'.
warn: Host.Startup[0]
Function 'Health' failed indexing and will be disabled.
我试过了
- 从
static
class 和方法更改为实例:无效
- 将每个 Function/method 放入单独的 classes 中:这行得通,但这可能只是一个 解决方法
- 在
4.0.1
(默认设置为 func init --worker-runtime dotnet --docker --language c#
)和当前 4.1.0
之间切换 Microsoft.NET.Sdk.Functions
:无效
我现在 运行 在容器中运行多年,但现在无法弄清楚我错过了什么。
我发现了你的问题,因为我遇到了同样的问题。可能与此有关:
https://github.com/Azure/azure-functions-host/issues/8244
根据 link 中的信息,我更改了 dockerfile 以将此图像用于 azure 函数:
FROM mcr.microsoft.com/azure-functions/dotnet:4.1.3-slim
这对我有用
我用这个 Dockerfile
Docker
执行了一个非常简单的函数应用程序
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace fapp1
{
public static class HttpIngress
{
[FunctionName("Health")]
public static IActionResult Health([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")] HttpRequest req) => new OkObjectResult("OK");
[FunctionName("HttpIngress")]
[return: ServiceBus("%queuename%", Connection = "servicebusconnection")]
public static async Task<string> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req)
=> await new StreamReader(req.Body).ReadToEndAsync();
}
}
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS installer-env
# Build requires 3.1 SDK
COPY --from=mcr.microsoft.com/dotnet/core/sdk:3.1 /usr/share/dotnet /usr/share/dotnet
COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish *.csproj --output /home/site/wwwroot
# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:4-appservice
FROM mcr.microsoft.com/azure-functions/dotnet:4
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
docker run -it --env-file docker.env test
对于 HttpIngress
中的两个函数,我收到此错误:
fail: Host.Startup[0]
Error indexing method 'Health'
Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'Health'
---> System.InvalidOperationException: Method overloads are not supported. There are multiple methods with the name 'fapp1.HttpIngress.Health'.
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndex.Add(IFunctionDefinition function, FunctionDescriptor descriptor, MethodInfo method) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndex.cs:line 30
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsyncCore(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 349
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 149
--- End of inner exception stack trace ---
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 157
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexTypeAsync(Type type, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 85
fail: Function.Health[0]
Microsoft.Azure.WebJobs.Host: Error indexing method 'Health'. Microsoft.Azure.WebJobs.Host: Method overloads are not supported. There are multiple methods with the name 'fapp1.HttpIngress.Health'.
warn: Host.Startup[0]
Function 'Health' failed indexing and will be disabled.
我试过了
- 从
static
class 和方法更改为实例:无效 - 将每个 Function/method 放入单独的 classes 中:这行得通,但这可能只是一个 解决方法
- 在
4.0.1
(默认设置为func init --worker-runtime dotnet --docker --language c#
)和当前4.1.0
之间切换Microsoft.NET.Sdk.Functions
:无效
我现在 运行 在容器中运行多年,但现在无法弄清楚我错过了什么。
我发现了你的问题,因为我遇到了同样的问题。可能与此有关:
https://github.com/Azure/azure-functions-host/issues/8244
根据 link 中的信息,我更改了 dockerfile 以将此图像用于 azure 函数:
FROM mcr.microsoft.com/azure-functions/dotnet:4.1.3-slim
这对我有用