I created an Azure function project in VS Code, using .NET 8 isolated. I followed the instructions here Develop Azure Functions by using Visual Studio Code and once I finished and deployed it, the basic function scaffolding worked. So I implemented access to a table in Azure storage.
My program.cs file is like this - the DependencyInjection package is not used:
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
var builder = FunctionsApplication.CreateBuilder(args);
// Agregar configuración de variables de entorno
builder.Configuration
.AddEnvironmentVariables() // Agrega variables de entorno
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true); // Para entornos locales
// Configurar servicios adicionales (si es necesario)
// builder.Services.AddTransient<IMyService, MyServiceImplementation>();
builder.ConfigureFunctionsWebApplication();
// Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4.
// builder.Services
// .AddApplicationInsightsTelemetryWorkerService()
// .ConfigureFunctionsApplicationInsights();
builder.Build().Run();
And this is my local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=false",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"TableStorageConnection": "azure-storage-connectionString",
"HelloWho": "Jon Doe Who"
},
"Host": {
"CORS": "*"
}
}
I created a very simple function called GetWho to try and read the connection string, because at some point, my function was not reading it and I got this in a log.
2024-11-26T02:15:50.309 [Information] Executing 'Functions.GetCities' (Reason='This function was programmatically called via the host APIs.', Id=67fcf38f-daa0-4433-9c54-f75331cd4dbc)
2024-11-26T02:15:50.657 [Information] Retrieving cities with registered open mics
2024-11-26T02:15:50.734 [Error] Function 'GetCities', Invocation id '67fcf38f-daa0-4433-9c54-f75331cd4dbc': An exception was thrown by the invocation.
Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: Function 'GetCities', Invocation id '67fcf38f-daa0-4433-9c54-f75331cd4dbc': An exception was thrown by the invocation.
Exception: System.ArgumentException: Value cannot be an empty string. (Parameter 'connectionString')
This is the GetWho method's code:
public class GetWho
{
private readonly ILogger<GetWho> _logger;
private readonly IConfiguration _configuration;
public GetWho(ILogger<GetWho> logger, IConfiguration configuration)
{
_logger = logger;
_configuration = configuration;
}
[Function("GetWho")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult($"Welcome to Azure Functions! {_configuration["HelloWho"]}");
}
}
Up here, all my functions are working ok on localhost. I get the values of the variables and GetCities returns the list I expect. The function is connected directly to Azure Storage, I am not using a local storage.
Once I deploy the function. It looks like it was deployed successfully, and I can see the functions listed in the App Services in Azure, but once I want to test run them, I get errors, but no logs or explicit error message. And the same thing happens when I click on "Get Function URL".
Curiously, there are no invocations recorded.
Another way of doing the program.cs I tried, was this. Same result. The DependencyInjection package is not used
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
namespace el_open_api
{
public class Program
{
public static void Main(string[] args)
{
var host = new HostBuilder()
.ConfigureAppConfiguration((context, config) =>
{
config.Sources.Clear();
config.AddEnvironmentVariables();
})
.ConfigureFunctionsWebApplication()
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();
}
}
}
I run out of talent at this point and can't get this to work. Any help is appreciated.







var builder = FunctionsApplication.CreateBuilder(args);I have always usedvar builder = new HostBuilder()instead, as per this: learn.microsoft.com/en-us/azure/azure-functions/… . It might not be relevant but can you try that instead? Also I struggled to find what your line actually does; the only reference seems to be for a .NET Aspire project rather than a conventional Functions project.