【问题标题】:Azure Webjob Unable Start Due to Binding Error由于绑定错误,Azure Webjob 无法启动
【发布时间】:2021-05-20 13:18:43
【问题描述】:

我有一个 Web 作业,它应该从 Azure 队列中读取,并对找到的有效负载执行一些操作。我遇到的问题是网络作业无法启动,这是错误

[02/17/2021 15:40:11 > e80592: INFO] [15:40:10 ERR] 错误索引方法“Functions.ProcessStudentPerfQueueMessages” [02/17/2021 15:40:11 > e80592:信息] Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException:错误索引方法“Functions.ProcessStudentPerfQueueMessages” [02/17/2021 15:40:11 > e80592: INFO] ---> System.InvalidOperationException: 无法将参数 'message' 绑定到类型 'StudentMessage'。 [02/17/2021 15:40:11 > e80592: INFO] 在 Microsoft.Azure.WebJobs.Host.Bindings.Data.ClassDataBindingProvider`1.TryCreateAsync(BindingProviderContext context) 在 C:\projects\azure-webjobs-sdk- rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\Data\ClassDataBindingProvider.cs:第 35 行 [02/17/2021 15:40:11 > e80592: INFO] 在 Microsoft.Azure.WebJobs.Host.Bindings.Data.DataBindingProvider.TryCreateAsync(BindingProviderContext context) 在 C:\projects\azure-webjobs-sdk-rqm4t\ src\Microsoft.Azure.WebJobs.Host\Bindings\Data\DataBindingProvider.cs:第 41 行 [02/17/2021 15:40:11 > e80592: INFO] 在 Microsoft.Azure.WebJobs.Host.Bindings.CompositeBindingProvider.TryCreateAsync(BindingProviderContext context) 在 C:\projects\azure-webjobs-sdk-rqm4t\src\ Microsoft.Azure.WebJobs.Host\Bindings\BindingProviders\CompositeBindingProvider.cs:第 23 行 [02/17/2021 15:40:11 > e80592:INFO] 在 Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsyncCore(MethodInfo 方法,IFunctionIndexCollector 索引,CancellationToken 取消令牌)在 C:\projects\azure-webjobs- sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:第 196 行 [02/17/2021 15:40:11 > e80592: INFO] 在 Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo 方法,IFunctionIndexCollector 索引,CancellationToken cancelToken) 在 C:\projects\azure-webjobs- sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:第 149 行 [02/17/2021 15:40:11 > e80592: INFO] --- 内部异常堆栈跟踪结束 --- [02/17/2021 15:40:11 > e80592: INFO] 在 Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo 方法,IFunctionIndexCollector 索引,CancellationToken cancelToken) 在 C:\projects\azure-webjobs- sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:第 157 行 [02/17/2021 15:40:11 > e80592: INFO] 在 C:\projects\azure-webjobs- 中的 Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexTypeAsync(类型类型,IFunctionIndexCollector 索引,CancellationToken 取消令牌) sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:第 85 行 [02/17/2021 15:40:13 > e80592: INFO] [15:40:13 FTL] Web 作业启动失败

这里是代码

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));
     }

目前队列中没有任何消息。 如果我将 StudentMessage 更改为 string,则 webjob 在 Azure 中成功启动。这是一个网络核心网络作业。请帮忙。

【问题讨论】:

标签: c# azure .net-core webjob


【解决方案1】:

这里是学生课

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 让我想到了StudentMessage 课程。我决定在 StudentMessage 中注释掉 Message 属性,然后砰!它成功启动了。一定是 Newtonsoft.json 的东西。

【讨论】:

  • 你为什么要标记你的答案?您的回答完全是多丽丝回答的副本。
  • 如果其他用户回答对你有用,你采纳可以加分。这样,更多的高分用户会帮助你解决技术问题。你总是自问自答,这是不好的行为。
【解决方案2】:

正如 Azure Function 的 document 所述:

使用字符串等方法参数访问消息数据 参数名称。您可以绑定到以下任何类型:

  • Object - Functions 运行时将 JSON 有效负载反序列化为 代码中定义的任意类的实例。

  • 字符串

  • 字节[]

  • 云队列消息

不确定你是如何定义StudentMessage类的,但是如果你可以通过使用string类型来满足你的需求,你可以考虑使用它。

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-04
    • 2014-08-10
    相关资源
    最近更新 更多