Reputation: 39
I am encountering an issue while debugging an Azure Function locally. The function is triggered via an HTTP request from Postman, and the terminal logs show that the function is being executed:
Executing 'Functions.KomponeraWebHook' (Reason='This function was programmatically called via the host APIs.', Id=22896f38-72f0-499c-baae-597abdf648e9)
However, the debugger does not hit the breakpoint inside the function, and Postman keeps waiting for a response indefinitely.
Local Settings: I Added local.settings.json after cloning from the repository. Deployment Status: The function works fine when deployed to Azure, so the issue seems to be isolated to local debugging.
Actually this issue occurs when i used the Service interface in the constructor's parameter
my program.cs
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Komponera;
using Microsoft.Extensions.Configuration;
using Komponera.service.event_trigger_service;
using Komponera.service.baseload_service;
using Komponera.service.Mongo_Services;
using Komponera.service.CommonServices;
using Komponera.service;
using Komponera.service.api_service;
using Komponera.service.Repository.Cms_Failed;
using NLog.Common;
using NLog;
using NLog.Extensions.Logging;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
using Komponera.Services.Common_Services;
using Komponera.Services.StoryReferenceValidation;
using Komponera.Repository.StoryCompletion;
LogManager.LoadConfiguration("nlog.config");
InternalLogger.LogToConsole = true;
InternalLogger.LogLevel = NLog.LogLevel.Trace;
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices((context, services) =>
{
var configuration = services.BuildServiceProvider()
.GetRequiredService<IConfiguration>();
//services.AddScoped<I>;
services.AddLogging(log =>
{
log.ClearProviders();
log.AddNLog();
}).Configure<LoggerFilterOptions>(options => options.MinLevel = LogLevel.Trace);
services.AddApplicationInsightsTelemetryWorkerService();
services.AddHttpClient();
services.ConfigureFunctionsApplicationInsights();
services.AddContentfulClient(configuration);
services.AddIMongoClient(configuration);
services.AddServiceBusClient(configuration);
services.AddScoped<IEventTriggerService, EventTriggerService>();
services.AddScoped<IBaseloadService, BaseloadService>();
services.AddScoped<ICmsEntryRepository, CmsEntryRepository>();
services.AddScoped<ICmsFailedRepository, CmsFailedRepository>();
services.AddScoped<ICmsNextSyncUrlRepository, CmsNextSyncUrlRepository>();
services.AddScoped<ICmsVersionMismatch, CmsVersionMismatch>();
services.AddScoped<IMappers, Mappers>();
services.AddScoped<ICommonServices,CommonServices>();
services.AddScoped<IApiService, ApiService>();
services.AddScoped<IReferenceValidation, ReferenceValidation>();
services.AddScoped<IStoryCollectionRepository, StoryCollectionRepository>();
})
.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true);
config.AddEnvironmentVariables();
})
.Build();
host.Run();
and my azure function code is
using Komponera.service.event_trigger_service;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
namespace Komponera
{
public class Function
{
private readonly ILogger<Function> _logger;
private readonly IEventTriggerService _IEventTriggerService;
public Function(ILogger<Function> logger,IEventTriggerService ieventTriggerService)
{
_logger = logger;
_IEventTriggerService = ieventTriggerService;
}
[Function("Function")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult("Welcome to Azure Functions!");
}
i get issue if i include the IEventTriggerService in contructor
Upvotes: 0
Views: 48
Reputation: 74
Normally, I would run the function from within the IDE with a mock request to debug. I am unfamiliar with using Postman to debug this locally as you describe here.
Here is an example for how to mock a request for local debugging with breakpoints: How do I mock the HttpRequest on an "azure function"
If you provide the local settings config, the IDE you are using, and any other relevant information, we might be able to give more specific advice.
Upvotes: 0