Reputation: 2453
Using .NET5 Azure function in Visual Studio 2019, I am getting the below exception from Program.cs:
System.InvalidOperationException: The gRPC channel URI 'http://0' could not be parsed
My Program.cs
is below:
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddSingleton<IConfiguration>(data =>
{
var result = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("AppSettings.json", false, true)
.AddJsonFile($"AppSettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
.AddEnvironmentVariables()
.Build();
return result;
});
services.AddSingleton<IServiceProvider, ServiceProvider>();
})
.UseDefaultServiceProvider(options => options.ValidateScopes = false)
.Build();
host.Run();
}
The exception is being thrown from host.Run()
in Debug mode. Any clue?
Upvotes: 29
Views: 33778
Reputation: 148
Use func start
instead of dotnet run
in your command line.
Im using VS Code and it worked for me.
Upvotes: 2
Reputation: 545
To solve this problem in visual studio code, in debugging select the option Attach to .NET Functions
as shown in following image.
Upvotes: -1
Reputation: 1
I worked with AzureFuction and when I has this error, I download azure-functions-core-tools npm and it solved issue.
Upvotes: 0
Reputation: 1008
On Rider it works after deleted bin
and obj
folders from previous project after a refactoring
Upvotes: 1
Reputation: 401
I have azure function project which was running fine with func start
command but I was not able to debug. After spending a day, I found the solution which is very basic solution which saved my day.
1) Open .vscode folder and add launch.json file if it does not exists, and add this to launch.json file.
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
2) open new terminal and run
azurite or azurite -l .\local
3) open new terminal and go to the directory of function project where your function .proj file lies. In my case it was like
cd .\project\myfunction\
4) Run func start --verbose
5) Click Run and Debug icon in the left sidebar
6) From the dropdown select .Net Core Attach
7) Click the play green icon to the left of the above dropdown.
8) Attach debugger to your function and call from postman etc. The default url
is http://localhost:7071/api/
9) Add your function name at the end like http://localhost:7071/api/myfunctionname
Upvotes: 3
Reputation: 4711
I had this error in Visual Studio 2022 after installing .NET8, F5 debug would no longer open into the local Azure Functions runtime.
To get it working again, I had to go to Tools -> Options -> Projects & Solutions -> Azure functions. Then check for updates and install updates, and restart Visual Studio.
This is documented in a GitHub issue here.
Upvotes: 1
Reputation: 21
For me it was a missing package. Microsoft.Azure.WebJobs.Extensions Fixed after a lot of pain
Upvotes: 0
Reputation: 45
I had this issue, in my case I had 2 installations of visual studio, one of them didn't have the "Azure development" workload included, and I was trying to run the Function app using that installation.
Upvotes: 1
Reputation: 11
I encountered this issue after installing VS Enterprise, even though I had previously been using the free version. For me, updating the Microsoft.Azure.Functions.Worker.Sdk
to the latest version resolved the problem.
Upvotes: 1
Reputation: 45
I had a similar issue and I found out that the problem was caused by the services.AddConfigurations
method in the ConfigureServices
extension method. This method was overriding the settings done by the ConfigureFunctionsWorkerDefaults()
method. To fix this, I had to include the hostContext.Configuration
in the AddConfigurations()
method, like this:
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices((hostContext, services) =>
{
var location = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
services.AddConfigurations(c => c.SetBasePath(location)
.AddJsonFile("example.settings.json", optional: false, reloadOnChange: true)
.AddConfiguration(hostContext.Configuration));
}).Build();
host.Run();
This way, the configuration from the hostContext
is merged with the configuration from the JSON file, and the settings are not overridden. I hope this helps you solve your problem.
Upvotes: -1
Reputation: 191
I was having the same problem in VS 2022, .NET 7. Adding the nuget package for
Microsoft.Azure.Functions.Worker.Sdk
solved this for me.
Upvotes: 15
Reputation: 121
In my case, shutting down Visual Studio 2022 and opening it in Administrator mode solved my issue
Upvotes: 7
Reputation: 2431
For me it was occurring in Rider. The issue was that I was running the Function App as a .Net Project instead of as Azure Functions host.
Upvotes: 74
Reputation: 2453
My issue has been solved. Once I set the IConfiguration
from ConfigureAppConfiguratio
middleware, the exception is gone
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureAppConfiguration(config =>
{
config.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("AppSettings.json", false, true)
.AddJsonFile(
$"AppSettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json",
true)
.AddEnvironmentVariables();
})
.ConfigureServices(services =>
{
})
.UseDefaultServiceProvider(options => options.ValidateScopes = false)
.Build();
host.Run();
}
Upvotes: 12