I am building a .NET Core 3.1 Azure Functions application on my local and am trying to configure a startup class. When I implement a class to inherit from FunctionsStartup I cannot import a .net core 3.1 class library into my project. If I do so and try to run the app, I get the following error in the execution window:
Microsoft.Azure.Functions.Extensions: Method not found: Microsoft.Extensions.Configuration.IConfigurationBuilder Microsoft.Azure.WebJobs.Hosting.IWebJobsConfigurationBuilder.get_ConfigurationBuilder()'. Value cannot be null. (Parameter 'provider')
When I switch the Startup base class to IWebJobsStartup the app starts fine. When I make a request and try stepping through the code I run into a problem. I can step through an initial portion of code (so I know my request is successfully received) but I am not able to step into one of my functions. I get a download prompt and a page opens up in the VS work area that has the error message TaskMethodInvker.cs not found with the tag line You need to find TaskMethodInvoker.cs to view the source for the current call stack frame. The below code shows my function:
[FunctionName("HttpAuth")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ExecutionContext context,
ILogger log)
{
GetAzureADConfiguration(context);
var jwt = GetJwtFromHeader(req);
}
private JwtSecurityToken GetSecurityToken(string encodedToken)
{
...
}
private string GetJwtFromHeader(HttpRequest req)
{
var authorizationHeader = req.Headers?["Authorization"];
string[] parts = authorizationHeader?.ToString().Split(null) ?? new string[0];
return (parts.Length == 2 && parts[0].Equals("Bearer")) ? parts[1] : string.Empty;
}
The GetAzureADConfiguration function is executing, GetJwtFromHeader is not.
It seems that any function trying to access the Header dictionary via code can not be stepped into and causes my error. However, if I inspect the object in the watch window, I see the correct value.
Here is my WebJobStartUp code:
[assembly: WebJobsStartup(typeof(StartUp))]
namespace CriticalPath.Api.Functions
{
class StartUp : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
...
}
}
}
Here is what I tried with FunctionsStartup
[assembly: FunctionsStartup(typeof(Startup))]
namespace CriticalPath.Api.Functions
{
class StartUp : FunctionsStartup
{
public void Configure(IWebJobsBuilder builder)
{
...
}
}
}
Why can't I step through my code that references the request's headers? What is the difference between FunctionsStartup and IWebJobsStartup. How do I access the headers if I want to use IWebJobsStartup?