Search code examples
azureazure-functionsremote-debugging

Azure Function Error Indexing Method - Remote Debugger crashes


I have an azure function app with everything working locally. I can publish the app to azure successfully, but all endpoints return 500 server errors.

My host logs look something like this:

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'.

My storage connection string is populated in azure portal appsettings along with my other settings from local.settings.json

I have also tried populating all my connection strings in the connection strings area in the azure portal as I have read local.settings.json should only be used locally.

I access these settings and connection strings with code similar to Environment.GetEnvironmentVariable("ReadDbConnectionDev");

Edit: have confirmed that connection strings are not the problem, as I tested with a new function without custom binding that was able to log them all correctly on my deployment. The problem here seems to lie with custom bindings.

I have a azure sql data store and a cosmos db mongo data store that I am connecting to. I am not using the cosmosdb binding in my function. Instead I am using a repository pattern with custom bindings to connect to it. Again, this works locally and I have already inquired that this should be able to work.

I am using a WebJobsStartUp and Extension as so.

[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));
        }
    }
}

I am using the latest 15.10.2009 version of azure function web job tools and 1.0.21 for Microsoft.NET.Sdk.Fuctions

When attaching a debugger to the remote function, my visual studio freezes and the breakpoints I set say breakpoint cannot be reached

Does anyone know what might be going on here?


Solution

  • So the issue was related to a bug that fails to write the extensions.json file to the remote host. I experienced it with the most recent sdk v1.0.19 and 1.0.21.

    This github issue seems to be tracking it.

    I was able to workaround the issue by copying my local extensions.json file over to the host machine with cloud explorer.