【Azure Function App】Function App出现500异常 Microsoft.Azure.WebJobs.Script.Workers.WorkerProcessExitException : C:\Program Files\dotnet\dotnet.exe exited with code -532462766 (0xE0434352)

问题描述

Azure Function App 中,出现了 500 错误,并伴随严重的后台异常:

Microsoft.Azure.WebJobs.Script.Workers.WorkerProcessExitException : C:\Program Files\dotnet\dotnet.exe exited with code -532462766 (0xE0434352)

进一步分析发现,该异常源于应用代码中的 System.InvalidOperationException,提示:

The property 'xxxxxxxxxID' has a temporary value while attempting to change the entity's state to 'Unchanged'.

这导致 Function App 的工作进程崩溃,随后重启恢复,但在高并发场景下仍可能再次触发。

 

问题解答

该问题本质上是 EF Core 实体属性配置不当导致的。xxxxxxxxxID字段在数据库中定义为:

[xxxxxxxxxID] [bigint] IDENTITY(1,1) NOT NULL

但代码中未显式声明其值生成策略,EF Core在跟踪实体状态时无法处理临时值,最终抛出异常并导致 dotnet 进程退出。

解决方案

方案一:在实体配置中显式声明该字段为自增:

builder.Property(e => e.RoutingAuditID).ValueGeneratedOnAdd();

方案二:或使用 Data Annotation:   

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]

public long RoutingAuditID { get; set; }

 

参考资料

PropertyBuilder<TProperty>.ValueGeneratedOnAdd 方法 : https://learn.microsoft.com/zh-cn/dotnet/api/microsoft.entityframeworkcore.metadata.builders.propertybuilder-1.valuegeneratedonadd?view=efcore-9.0

 

posted @ 2025-11-26 10:22  路边两盏灯  阅读(0)  评论(0)    收藏  举报