首页 > 解决方案 > Azure 函数错误索引方法 - 远程调试器崩溃

问题描述

我有一个天蓝色的功能应用程序,一切都在本地工作。我可以成功地将应用程序发布到 azure,但所有端点都返回 500 个服务器错误。

我的主机日志如下所示:

2018-09-17T15:05:14.801 [Information] Host Status: {
  "id": "---function",
  "state": "Default",
  "version": "2.0.12095.0",
  "versionDetails": "2.0.12095.0-rc1 Commit hash: beb6b6afde701a57----c051c082e2d1c738e18"
}
2018-09-17T15:05:16.555 [Information] Generating 11 job function(s)
2018-09-17T15:05:16.576 [Error] Error indexing method 'AddMaterial.Run'
2018-09-17T15:05:16.657 [Warning] Function 'AddMaterial.Run' failed indexing and will be disabled.
2018-09-17T15:05:16.658 [Error] Error indexing method 'ChangeMaterialWeight.Run'
2018-09-17T15:05:16.714 [Warning] Function 'ChangeMaterialWeight.Run' failed indexing and will be disabled.
2018-09-17T15:05:16.766 [Error] Error indexing method 'CheckIfOldestMaterial.Run'
2018-09-17T15:05:16.863 [Warning] Function 'CheckIfOldestMaterial.Run' failed indexing and will be disabled.
2018-09-17T15:05:16.864 [Error] Error indexing method 'CreateBoxType.Run'
2018-09-17T15:05:16.915 [Warning] Function 'CreateBoxType.Run' failed indexing and will be disabled.
2018-09-17T15:05:16.916 [Error] Error indexing method 'CreateFinishedGoods.Run'
2018-09-17T15:05:16.961 [Warning] Function 'CreateFinishedGoods.Run' failed indexing and will be disabled.
2018-09-17T15:05:16.962 [Error] Error indexing method 'CreateWarehouse.Run'
2018-09-17T15:05:17.005 [Warning] Function 'CreateWarehouse.Run' failed indexing and will be disabled.
2018-09-17T15:05:17.006 [Error] Error indexing method 'WarehousesAll.Run'
2018-09-17T15:05:17.053 [Warning] Function 'WarehousesAll.Run' failed indexing and will be disabled.
2018-09-17T15:05:17.054 [Error] Error indexing method 'MaterialByRollId.Run'
2018-09-17T15:05:17.115 [Warning] Function 'MaterialByRollId.Run' failed indexing and will be disabled.
2018-09-17T15:05:17.116 [Error] Error indexing method 'MaterialsByMaterialNumber.Run'
2018-09-17T15:05:17.177 [Warning] Function 'MaterialsByMaterialNumber.Run' failed indexing and will be disabled.
2018-09-17T15:05:17.178 [Error] Error indexing method 'MoveFinishedGoods.Run'
2018-09-17T15:05:17.220 [Warning] Function 'MoveFinishedGoods.Run' failed indexing and will be disabled.
2018-09-17T15:05:17.220 [Error] Error indexing method 'MoveMaterial.Run'
2018-09-17T15:05:17.256 [Warning] Function 'MoveMaterial.Run' failed indexing and will be disabled.
2018-09-17T15:05:17.258 [Warning] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
2018-09-17T15:05:17.258 [Information] Host initialized (2497ms)
2018-09-17T15:05:17.262 [Information] Host started (2501ms)
2018-09-17T15:05:17.266 [Information] Job host started
2018-09-17T15:05:22.298 [Information] Host lock lease acquired by instance ID '130a20de31f46----dc65791c3078124'.

我的存储连接字符串与 local.settings.json 中的其他设置一起填充在 azure 门户 appsettings 中

我还尝试在 azure 门户的连接字符串区域中填充所有连接字符串,因为我已阅读 local.settings.json 只能在本地使用。

我使用类似于以下的代码访问这些设置和连接字符串Environment.GetEnvironmentVariable("ReadDbConnectionDev");

编辑: 已确认连接字符串不是问题,因为我使用没有自定义绑定的新功能进行了测试,该功能能够在我的部署中正确记录它们。这里的问题似乎在于自定义绑定。

我有一个 azure sql 数据存储和一个我要连接的 cosmos db mongo 数据存储。我没有在我的函数中使用 cosmosdb 绑定。相反,我使用带有自定义绑定的存储库模式来连接它。同样,这在本地工作,我已经询问这应该能够工作。

我正在使用 WebJobsStartUp 和 Extension 。

[assembly: WebJobsStartup(typeof(FunctionStartUp), name: "ESPI Function Startup Extension")]
namespace ESPIWarehouseFunction
{
    public class FunctionStartUp : IWebJobsStartup
    {
        public void Configure(IWebJobsBuilder builder)
        {
            //Don't need to create a new service collection just use the built-in one
            builder.Services.AddSingleton<IQueryService, QueryService>();
            builder.Services.AddSingleton<IWarehouseStateRepository, WarehouseStateRepository>();
            builder.Services.AddSingleton<IMaterialRepository, MaterialRepository>();
            builder.Services.AddSingleton<IEventRepository, EventRepository>();
            builder.Services.AddSingleton<IBoxRepository, BoxRepository>();
            builder.Services.AddSingleton<IReadContext, ReadContext>();
            builder.Services.AddSingleton<IStateContext, StateContext>();
            builder.Services.AddSingleton<IStateContext, StateContext>();
            builder.Services.AddSingleton<IEventStoreContext, EventStoreContext>();
            builder.Services.AddMediatR(typeof(FunctionStartUp).GetTypeInfo().Assembly);

            //Registering an extension
            builder.AddExtension<InjectConfiguration>();
        }
    }
}


namespace ESPIWarehouseFunction.Injection
{
    public class InjectConfiguration : IExtensionConfigProvider
    {
        private IServiceProvider _serviceProvider;

        public InjectConfiguration(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        public void Initialize(ExtensionConfigContext context)
        {
            var services = new ServiceCollection();
            RegisterServices(services);
            _serviceProvider = services.BuildServiceProvider(true);

            context
                .AddBindingRule<InjectAttribute>()
                .BindToInput<dynamic>(i => _serviceProvider.GetRequiredService(i.Type));
        }
        private void RegisterServices(IServiceCollection services)
        {
            services.AddSingleton<IWarehouseStateRepository, WarehouseStateRepository>();
            services.AddSingleton<IQueryService, QueryService>();
            services.AddSingleton<IMaterialRepository, MaterialRepository>();
            services.AddSingleton<IEventRepository, EventRepository>();
            services.AddSingleton<IBoxRepository, BoxRepository>();
            services.AddSingleton<IReadContext, ReadContext>();
            services.AddSingleton<IStateContext, StateContext>();
            services.AddSingleton<IStateContext, StateContext>();
            services.AddSingleton<IEventStoreContext, EventStoreContext>();
            services.AddMediatR(typeof(InjectConfiguration));
        }
    }
}

我正在使用最新的15.10.2009 版本的 azure function web job tools 和1.0.21 for Microsoft.NET.Sdk.Fuctions

将调试器附加到远程功能时,我的视觉工作室冻结并且我设置的断点说breakpoint cannot be reached

有谁知道这里可能会发生什么?

标签: azureazure-functionsremote-debugging

解决方案


所以这个问题与无法将 extensions.json 文件写入远程主机的错误有关。我用最新的 sdk v1.0.19 和 1.0.21 体验过。

这个github 问题似乎正在跟踪它。

我可以通过使用云资源管理器将本地 extensions.json 文件复制到主机来解决此问题。


推荐阅读