You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署到Azure的C# Azure Function无法在门户显示及触发器异常

问题:C# Azure Function部署后无法找到HTTP触发器

我通过VS Code将C# Azure Function部署到Azure后,在Azure门户中找不到该函数,且出现“No HTTP Triggers”提示。但用Azure Function扩展部署Python函数一切正常,用AZ CLI部署C#函数也会遇到同样问题。


VS Code部署日志

14:57:32 functionapp: Processed 496 files...
14:57:52 functionapp: Processed 719 files...
14:58:00 functionapp: Finished successfully.
14:58:01 functionapp: Running post deployment command(s)...
14:58:01 functionapp: Triggering recycle (preview mode disabled).
14:58:01 functionapp: Deployment successful.
14:58:15 functionapp: Syncing triggers...
14:58:25 functionapp: Querying triggers...
14:58:26 functionapp: No HTTP triggers found.

AZ CLI部署输出

az functionapp deployment source config-zip -g rg-name -n functionapp --src publish_output.zip
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
{
    "active": true,
    "author": "N/A",
    "author_email": "N/A",
    "complete": true,
    "deployer": "ZipDeploy",
    "end_time": "2023-03-29T13:11:34.0203343Z",
    "is_readonly": true,
    "is_temp": false,
    "last_success_end_time": "2023-03-29T13:11:34.0203343Z",
    "log_url": "https://functionapp.scm.azurewebsites.net/api/deployments/latest/log",
    "message": "Created via a push deployment",
    "progress": "",
    "provisioningState": "Succeeded",
    "received_time": "2023-03-29T13:10:35.008044Z",
    "site_name": "functionapp",
    "start_time": "2023-03-29T13:10:35.8988656Z",
    "status": 4,
    "status_text": "",
    "url": "https://functionapp.scm.azurewebsites.net/api/deployments/latest"
  }

依赖注入代码片段

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

[assembly: FunctionsStartup(typeof(A.Startup))]

namespace A
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddSingleton<IHelper, Helper>();
            builder.Services.AddSingleton<
                SomeInterface,
                SomeClass
            >();
        }
    }
}

函数类构造及触发器代码

namespace A
{
    public class FunctionApp
    {
        private IHelper _helper;
        private SomeInterface _someInterface;

        public FunctionApp(
            IHelper helper,
            SomeInterface someInterface
        )
        {
            _helper = helper;
            _someInterface = someInterface;
        }

        /// <summary>
        /// The function's entry point.
        /// </summary>
        /// <param name="req"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        [FunctionName("FunctionApp")]
        public async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log
        )
        // The code starts here

可能的原因分析
  • 程序集版本不兼容:检查Microsoft.Azure.Functions.Extensions.DependencyInjection包版本是否与Azure Functions运行时匹配,版本过高或过低会导致启动类无法加载,影响触发器发现。
  • 启动类配置错误:确认[assembly: FunctionsStartup(typeof(A.Startup))]中的命名空间和类名完全正确,特性必须指向实际的Startup类。
  • 依赖注入初始化失败:检查IHelper、SomeInterface的实现类是否存在编译错误或未处理异常,若启动时抛出异常,函数宿主无法正常初始化,触发器无法被识别。
  • 发布包不完整:确认dotnet publish生成的包包含所有必要的dll和配置文件,遗漏关键程序集会导致函数代码无法加载。
  • 运行时版本不匹配:检查Azure门户中函数应用的运行时版本是否与本地开发环境一致(比如本地用.NET 6,Azure配置为.NET 3.1),版本不兼容会导致代码无法运行。
  • 触发器同步异常:部署后的触发器同步可能存在延迟或失败,可在Azure门户手动触发同步(进入“函数”页面点击“同步”),或重启函数应用后再检查。
  • 类访问修饰符问题:确保FunctionApp类是public修饰(代码中已满足,但需确认无修改),非公开类无法被函数宿主识别。

内容的提问来源于stack exchange,提问作者Fares

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 07:37:49