In VS Code, I created a new Function app using the command palette (Azure Static Web Apps: Create HTTP Function). I used C# as the Function language.
The following reference was added to the csproj file.
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
The first function works fine
[FunctionName("GetDocumentSignatureStatus")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.User, "get", Route = "departments/{dept:alpha}/documents/{doc}/versions/{version}/signatures/{userId}")]
HttpRequest req, ILogger log,
string dept, string doc, string version, string userId)
{
//implementation
}
I added a a second function within the same class with this signature.
[FunctionName("SignDocumentForUser")]
public static async Task<IActionResult> Sign(
[HttpTrigger(AuthorizationLevel.User, "post", Route = "departments/{dept:alpha}/documents/{doc}/versions/{version}/signatures")]
HttpRequest req,
ILogger log,
string dept, string doc, string version,
[FromBody]UserSignature signature)
{
//implementation
}
The first function ("GetDocumentSignatureStatus") works as expected from my static web app. The second ("SignDocumentForUser") does not work and gives the following error.
[api] [2023-07-11T17:16:16.321Z] An unhandled host error has occurred. [api] [2023-07-11T17:16:16.321Z] Microsoft.Azure.WebJobs.Host: 'SignDocumentForUser' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?.
I run the app from the Terminal in VS Code using
edit:
swa start --host=localhost --port=3010 --app-devserver-url=http:/localhost:7071 --run "npm start"
I've tried using the command palette to create a second Http Function.
I've also tried following suggestions from here and here.
After trying Ikhtesam Afrin's suggestion, I was prompted to look into the build output where I found this.
[api] [2023-07-14T13:17:41.768Z] Microsoft.Azure.WebJobs.Host: Error indexing method 'SignDocumentForUser'ure. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azod for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), bui [api] [2023-07-14T13:17:41.773Z] Error indexing method 'SignDocumentForUser'
If I remove the [FromBody] parameter, the endpoint works. I cannot get the function to bind to that body parameter.