Search code examples
c#azure.net-corewebjob

Azure Webjob Unable Start Due to Binding Error


I have a webjob that is supposed to read from an Azure queue and do something with the payload found. The issue I'm having is the webjob won't start and here is the error

[02/17/2021 15:40:11 > e80592: INFO] [15:40:10 ERR] Error indexing method 'Functions.ProcessStudentPerfQueueMessages' [02/17/2021 15:40:11 > e80592: INFO] Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'Functions.ProcessStudentPerfQueueMessages' [02/17/2021 15:40:11 > e80592: INFO] ---> System.InvalidOperationException: Can't bind parameter 'message' to type 'StudentMessage'. [02/17/2021 15:40:11 > e80592: INFO] at Microsoft.Azure.WebJobs.Host.Bindings.Data.ClassDataBindingProvider`1.TryCreateAsync(BindingProviderContext context) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\Data\ClassDataBindingProvider.cs:line 35 [02/17/2021 15:40:11 > e80592: INFO] at Microsoft.Azure.WebJobs.Host.Bindings.Data.DataBindingProvider.TryCreateAsync(BindingProviderContext context) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\Data\DataBindingProvider.cs:line 41 [02/17/2021 15:40:11 > e80592: INFO] at Microsoft.Azure.WebJobs.Host.Bindings.CompositeBindingProvider.TryCreateAsync(BindingProviderContext context) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\BindingProviders\CompositeBindingProvider.cs:line 23 [02/17/2021 15:40:11 > e80592: INFO] at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsyncCore(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 196 [02/17/2021 15:40:11 > e80592: INFO] at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 149 [02/17/2021 15:40:11 > e80592: INFO] --- End of inner exception stack trace --- [02/17/2021 15:40:11 > e80592: INFO] at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 157 [02/17/2021 15:40:11 > e80592: INFO] at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexTypeAsync(Type type, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 85 [02/17/2021 15:40:13 > e80592: INFO] [15:40:13 FTL] Web Job start-up failed

Here is the code

public class Functions
{
    private readonly IService _service;
    public Functions(IService service)
    {
         _service = service;
    }
    public async Task ProcessStudentPerfQueueMessages([QueueTrigger("studentperf")] StudentMessage message)
    {
         await new StudentPerfQueueProcessor(_pascoService).ProcessMessage(message));
     }

There aren't any messages in the queue at the moment. If I change StudentMessage to a string then the webjob starts successfully in Azure. This is a Net Core Webjob. Please help.


Solution

  • Here is the student class

    public class StudentMessage
    {
       public int StudentId { get; set; }
       public int SubjectId { get; set; }
       public StudentForm Form { get; set; }
       public Dictionary<int, AnswerStatus> QuestionAnswerStatus { get; set; }
       public string Message { get; set; }
       public DateTime Date { get; set; }
    }
    

    Doris Lv got me thinking about the StudentMessage class. I decided to comment out the Message property in the StudentMessage and bam!! It started successfully. Must be something with the Newtonsoft.json.