首页 > 解决方案 > HangFire“无法访问已处置的对象。对象名称:'SqlDelegatedTransaction'”

问题描述

在 Visual Studio Mac 中寻找有关 HangFire 的帮助。”这是一个在 Windows / IIS 上运行的 WebAPI 项目。

在启动过程中,HangFire 被初始化。一旦发生这种情况,我们会尝试设置一个经常性的工作。当连接到 Windows 上的 SQL Server 2014 或 Linux 上的 SQL Server 2019 CTP 时,这会引发异常。

{System.Transactions.TransactionAbortedException: Transaction failed ---> System.ObjectDisposedException: Cannot access a disposed object. Object name: 'SqlDelegatedTransaction'. at System.Data.SqlClient.SqlDelegatedTransaction.GetValidConnection () [0x0000a]…}

连接到 Azure SQL 时,它返回 {System.NotImplementedException: The method or operation is not implemented. at System.Transactions.Transaction.EnlistPromotableSinglePhase (System.Transactions.IPromotableSinglePhaseNotification promotableSinglePhaseNotification, System.Guid promoterType)

尝试了 HangFire 1.6.8(适用于 Windows)、1.6.14 和 1.6.21。

调用BackgroundJob.Enqueue或 时抛出错误RecurringJob.AddOrUpdate

为了简化这一点,我实现了一个简单的函数而不是我们的,这也失败了。

例如 BackgroundJob.Enqueue(() => Console.Write("Enqueue"));

任何帮助,将不胜感激!

标签: c#asp.net-web-apitransactionsmonohangfire

解决方案


我找到了解决此问题的方法...我必须下载 HangFire 的源代码,将项目添加为引用并将 HangFire.SQLServer 项目设置为在没有“NETFULL”符号的情况下进行编译。


推荐阅读