gpt4 book ai didi

c# - 在本地运行 Azure Functions 显示找到 1 个函数,但加载了 0 个函数,并且该函数不起作用

转载 作者:行者123 更新时间:2023-12-02 06:12:11 28 4
gpt4 key购买 nike

我有一个 Azure Http 触发器函数,该函数构建成功并且运行时没有错误,但它没有加载该函数。当前运行输出以详细模式给出以下内容: Run output

在使用 Postman 测试端点时,出于明显的原因,它给了我 404 HTTP 响应。为了解决这个问题,我尝试了与函数本身相关的多种可能性,例如:

  • 项目类型不正确
  • 缺少功能触发器以及与其相关的任何问题
  • 无效的函数签名
  • 缺少 Nuget 软件包
  • local.settings.json 不正确
  • host.json 不正确
  • 运行配置
  • 查看运行和构建时的详细日志输出以获取任何指针

最初的假设是,这是由于我正在开发的功能造成的,但进一步的调查表明,我想要在本地运行和调试的所有本地开发功能都会发生这种情况(在多个 IDE 和终端中使用新的测试功能)。这指出了一个更全局性的问题。目前使用 JetRider 运行它,但也尝试使用 Visual Studio 并直接命令行执行。

使用 azure 函数Azure Functions 核心工具:4.0.4915函数运行时版本:4.14.0.19631框架:.net 6.0语言:C#

问题:可能是什么原因造成的以及如何解决?

更新:

在调查时发现 func 没有从项目函数根读取 host.jsonlocal.settings.json 。如何纠正这个问题以从项目中读取它?

最佳答案

我使用 Http 触发器获取了 .NET 6 Azure 函数,并使用命令 func host start --verbose 运行该函数,然后我在控制台/终端中收到以下日志:

PS C:\Users\Hari\Azure Functions\KrishNet6FunApp104> func host start --verbose
MSBuild version 17.4.1+9a89d02ff for .NET
Determining projects to restore...
All projects are up-to-date for restore.
KrishNet6FunApp104 -> C:\Users\Hari\Azure Functions\KrishNet6FunApp104\bin\output\KrishNet6FunApp104.dll

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:14.49



%%%%%%
%%%%%%
@ %%%%%% @
@@ %%%%%% @@
@@@ %%%%%%%%%%% @@@
@@ %%%%%%%%%% @@
@@ %%%% @@
@@ %%% @@
@@ %% @@
%%
%


Azure Functions Core Tools
Core Tools Version: 4.0.4915 Commit hash: N/A (64-bit)
Function Runtime Version: 4.14.0.19631

[2023-02-14T07:11:40.662Z] Found C:\Users\Hari\Azure Functions\KrishNet6FunApp104\KrishNet6FunApp104.csproj. Using for user secrets file configuration.
[2023-02-14T07:11:42.596Z] Building host: version spec: , startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '6d9cc98b-20c2-463b-822a-05cf23ae8998'
[2023-02-14T07:11:42.617Z] Reading host configuration file 'C:\Users\Hari\Azure Functions\KrishNet6FunApp104\bin\output\host.json'
[2023-02-14T07:11:42.622Z] Host configuration file read:
[2023-02-14T07:11:42.624Z] {
[2023-02-14T07:11:42.626Z] "version": "2.0",
[2023-02-14T07:11:42.627Z] "logging": {
[2023-02-14T07:11:42.628Z] "applicationInsights": {
[2023-02-14T07:11:42.630Z] "samplingSettings": {
[2023-02-14T07:11:42.631Z] "isEnabled": true,
[2023-02-14T07:11:42.633Z] "excludedTypes": "Request"
[2023-02-14T07:11:42.635Z] }
[2023-02-14T07:11:42.636Z] }
[2023-02-14T07:11:42.638Z] }
[2023-02-14T07:11:42.639Z] }
[2023-02-14T07:11:42.671Z] Loading extensions from C:\Users\Hari\Azure Functions\KrishNet6FunApp104\bin\output\bin. BundleConfigured: False, PrecompiledFunctionApp: False, LegacyBundle: False
[2023-02-14T07:11:42.674Z] Script Startup resetting load context with base path: 'C:\Users\Hari\Azure Functions\KrishNet6FunApp104\bin\output\bin'.
[2023-02-14T07:11:42.707Z] Reading host configuration file 'C:\Users\Hari\Azure Functions\KrishNet6FunApp104\bin\output\host.json'
[2023-02-14T07:11:42.709Z] Host configuration file read:
[2023-02-14T07:11:42.711Z] {
[2023-02-14T07:11:42.714Z] "version": "2.0",
[2023-02-14T07:11:42.716Z] "logging": {
[2023-02-14T07:11:42.717Z] "applicationInsights": {
[2023-02-14T07:11:42.719Z] "samplingSettings": {
[2023-02-14T07:11:42.721Z] "isEnabled": true,
[2023-02-14T07:11:42.723Z] "excludedTypes": "Request"
[2023-02-14T07:11:42.724Z] }
[2023-02-14T07:11:42.725Z] }
[2023-02-14T07:11:42.727Z] }
[2023-02-14T07:11:42.728Z] }
[2023-02-14T07:11:43.950Z] Initializing Warmup Extension.
[2023-02-14T07:11:44.090Z] Initializing Host. OperationId: '6d9cc98b-20c2-463b-822a-05cf23ae8998'.
[2023-02-14T07:11:44.115Z] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=6d9cc98b-20c2-463b-822a-05cf23ae8998
[2023-02-14T07:11:44.173Z] LoggerFilterOptions
[2023-02-14T07:11:44.174Z] {
[2023-02-14T07:11:44.176Z] "MinLevel": "None",
[2023-02-14T07:11:44.178Z] "Rules": [
[2023-02-14T07:11:44.180Z] {
[2023-02-14T07:11:44.182Z] "ProviderName": null,
[2023-02-14T07:11:44.183Z] "CategoryName": null,
[2023-02-14T07:11:44.185Z] "LogLevel": null,
[2023-02-14T07:11:44.187Z] "Filter": "<AddFilter>b__0"
[2023-02-14T07:11:44.190Z] },
[2023-02-14T07:11:44.192Z] {
[2023-02-14T07:11:44.193Z] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2023-02-14T07:11:44.195Z] "CategoryName": null,
[2023-02-14T07:11:44.197Z] "LogLevel": "None",
[2023-02-14T07:11:44.199Z] "Filter": null
[2023-02-14T07:11:44.200Z] },
[2023-02-14T07:11:44.202Z] {
[2023-02-14T07:11:44.204Z] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2023-02-14T07:11:44.206Z] "CategoryName": null,
[2023-02-14T07:11:44.208Z] "LogLevel": null,
[2023-02-14T07:11:44.210Z] "Filter": "<AddFilter>b__0"
[2023-02-14T07:11:44.212Z] },
[2023-02-14T07:11:44.214Z] {
[2023-02-14T07:11:44.216Z] "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2023-02-14T07:11:44.218Z] "CategoryName": null,
[2023-02-14T07:11:44.220Z] "LogLevel": null,
[2023-02-14T07:11:44.222Z] "Filter": "<AddFilter>b__0"
[2023-02-14T07:11:44.224Z] }
[2023-02-14T07:11:44.226Z] ]
[2023-02-14T07:11:44.231Z] }
[2023-02-14T07:11:44.234Z] LoggerFilterOptions
[2023-02-14T07:11:44.236Z] {
[2023-02-14T07:11:44.238Z] "MinLevel": "None",
[2023-02-14T07:11:44.241Z] "Rules": [
[2023-02-14T07:11:44.243Z] {
[2023-02-14T07:11:44.245Z] "ProviderName": null,
[2023-02-14T07:11:44.249Z] "CategoryName": null,
[2023-02-14T07:11:44.251Z] "LogLevel": null,
[2023-02-14T07:11:44.253Z] "Filter": "<AddFilter>b__0"
[2023-02-14T07:11:44.255Z] },
[2023-02-14T07:11:44.260Z] {
[2023-02-14T07:11:44.266Z] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2023-02-14T07:11:44.268Z] "CategoryName": null,
[2023-02-14T07:11:44.271Z] "LogLevel": "None",
[2023-02-14T07:11:44.274Z] "Filter": null
[2023-02-14T07:11:44.276Z] },
[2023-02-14T07:11:44.278Z] {
[2023-02-14T07:11:44.281Z] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2023-02-14T07:11:44.283Z] "CategoryName": null,
[2023-02-14T07:11:44.286Z] "LogLevel": null,
[2023-02-14T07:11:44.288Z] "Filter": "<AddFilter>b__0"
[2023-02-14T07:11:44.291Z] },
[2023-02-14T07:11:44.294Z] {
[2023-02-14T07:11:44.297Z] "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2023-02-14T07:11:44.300Z] "CategoryName": null,
[2023-02-14T07:11:44.303Z] "LogLevel": null,
[2023-02-14T07:11:44.305Z] "Filter": "<AddFilter>b__0"
[2023-02-14T07:11:44.310Z] }
[2023-02-14T07:11:44.313Z] ]
[2023-02-14T07:11:44.315Z] }
[2023-02-14T07:11:44.317Z] ConcurrencyOptions
[2023-02-14T07:11:44.320Z] {
[2023-02-14T07:11:44.322Z] "DynamicConcurrencyEnabled": false,
[2023-02-14T07:11:44.326Z] "MaximumFunctionConcurrency": 500,
[2023-02-14T07:11:44.332Z] "CPUThreshold": 0.8,
[2023-02-14T07:11:44.335Z] "SnapshotPersistenceEnabled": true
[2023-02-14T07:11:44.337Z] }
[2023-02-14T07:11:44.339Z] FunctionResultAggregatorOptions
[2023-02-14T07:11:44.343Z] {
[2023-02-14T07:11:44.346Z] "BatchSize": 1000,
[2023-02-14T07:11:44.350Z] "FlushTimeout": "00:00:30",
[2023-02-14T07:11:44.353Z] "IsEnabled": true
[2023-02-14T07:11:44.357Z] }
[2023-02-14T07:11:44.361Z] SingletonOptions
[2023-02-14T07:11:44.366Z] {
[2023-02-14T07:11:44.372Z] "LockPeriod": "00:00:15",
[2023-02-14T07:11:44.376Z] "ListenerLockPeriod": "00:00:15",
[2023-02-14T07:11:44.379Z] "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[2023-02-14T07:11:44.383Z] "LockAcquisitionPollingInterval": "00:00:05",
[2023-02-14T07:11:44.385Z] "ListenerLockRecoveryPollingInterval": "00:01:00"
[2023-02-14T07:11:44.387Z] }
[2023-02-14T07:11:44.393Z] Starting JobHost
[2023-02-14T07:11:44.405Z] Starting Host (HostId=c1ml47687ms-778510111, InstanceId=454fc6f1-0750-4023-b206-73112827b0d6, Version=4.14.0.19631, ProcessId=5892, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
[2023-02-14T07:11:44.483Z] Loading functions metadata
[2023-02-14T07:11:44.491Z] Reading functions metadata
[2023-02-14T07:11:44.497Z] Reading functions metadata
[2023-02-14T07:11:44.524Z] 1 functions found
[2023-02-14T07:11:44.531Z] 1 functions found
[2023-02-14T07:11:44.566Z] Reading functions metadata
[2023-02-14T07:11:44.622Z] 1 functions found
[2023-02-14T07:11:44.626Z] 1 functions loaded
[2023-02-14T07:11:45.667Z] Generating 1 job function(s)
[2023-02-14T07:11:45.771Z] Found the following functions:
[2023-02-14T07:11:45.773Z] KrishNet6FunApp104.Function1.Run
[2023-02-14T07:11:45.775Z]
[2023-02-14T07:11:45.805Z] HttpOptions
[2023-02-14T07:11:45.807Z] {
[2023-02-14T07:11:45.809Z] "DynamicThrottlesEnabled": false,
[2023-02-14T07:11:45.810Z] Initializing function HTTP routes
[2023-02-14T07:11:45.812Z] "EnableChunkedRequestBinding": false,
[2023-02-14T07:11:45.814Z] Mapped function route 'api/Function1' [get,post] to 'Function1'
[2023-02-14T07:11:45.816Z] "MaxConcurrentRequests": -1,
[2023-02-14T07:11:45.818Z]
[2023-02-14T07:11:45.820Z] "MaxOutstandingRequests": -1,
[2023-02-14T07:11:45.825Z] "RoutePrefix": "api"
[2023-02-14T07:11:45.830Z] }
[2023-02-14T07:11:45.855Z] Host initialized (1410ms)
[2023-02-14T07:11:45.865Z] Host started (1453ms)
[2023-02-14T07:11:45.868Z] Job host started

Functions:

Function1: [GET,POST] http://localhost:7071/api/Function1

我观察到,在生成和验证项目中找到的函数数量之前,运行时工作线程正在读取函数元数据: enter image description here

在同一项目中创建第二个 Http 触发函数后:

[2023-02-14T08:45:23.800Z] Starting JobHost
[2023-02-14T08:45:23.804Z] Starting Host (HostId=c1ml47687ms-778510111, InstanceId=08cbea94-a74d-4167-892f-9802ed417b9a, Version=4.14.0.19631, ProcessId=18812, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
[2023-02-14T08:45:23.829Z] Loading functions metadata
[2023-02-14T08:45:23.834Z] Reading functions metadata
[2023-02-14T08:45:23.837Z] Reading functions metadata
[2023-02-14T08:45:23.849Z] 2 functions found
[2023-02-14T08:45:23.854Z] 2 functions found
[2023-02-14T08:45:23.867Z] Reading functions metadata
[2023-02-14T08:45:23.882Z] 1 functions found
[2023-02-14T08:45:23.886Z] 2 functions loaded
[2023-02-14T08:45:24.100Z] Generating 2 job function(s)
[2023-02-14T08:45:24.145Z] Found the following functions:
[2023-02-14T08:45:24.147Z] KrishNet6FunApp104.Function1.Run
[2023-02-14T08:45:24.149Z] Company.Function.Function2.Run
[2023-02-14T08:45:24.150Z]
[2023-02-14T08:45:24.161Z] HttpOptions
[2023-02-14T08:45:24.163Z] Initializing function HTTP routes
[2023-02-14T08:45:24.163Z] {
[2023-02-14T08:45:24.165Z] Mapped function route 'api/Function1' [get,post] to 'Function1'
[2023-02-14T08:45:24.168Z] "DynamicThrottlesEnabled": false,
[2023-02-14T08:45:24.169Z] Mapped function route 'api/Function2' [get,post] to 'Function2'
[2023-02-14T08:45:24.170Z] "EnableChunkedRequestBinding": false,
[2023-02-14T08:45:24.171Z]
[2023-02-14T08:45:24.172Z] "MaxConcurrentRequests": -1,
[2023-02-14T08:45:24.174Z] "MaxOutstandingRequests": -1,
[2023-02-14T08:45:24.175Z] "RoutePrefix": "api"
[2023-02-14T08:45:24.176Z] }
[2023-02-14T08:45:24.185Z] Host initialized (365ms)
[2023-02-14T08:45:24.192Z] Host started (384ms)
[2023-02-14T08:45:24.194Z] Job host started

Functions:

Function1: [GET,POST] http://localhost:7071/api/Function1
Function2: [GET,POST] http://localhost:7071/api/Function2

enter image description here

此函数元数据特定于触发器类型,例如 Http、队列、Blob 存储等。

对于 Http 触发器,它期望名称类型方向应正确映射到本 MS 文档中提到的绑定(bind)元数据1 & 2

所有这些绑定(bind)将在 Http 触发器类文件的函数声明中提供 - 本地创建的 cSharp Azure 函数。

这是 GitHub Repository ,我已经推送了我的Azure Functions (.NET 6 Stack) - Http Trigger项目代码供大家引用。

关于c# - 在本地运行 Azure Functions 显示找到 1 个函数,但加载了 0 个函数,并且该函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75435901/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com