From e615b31924282d3c6c60fdad8a821bb06655fea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SAL=C4=B0H=20=C3=96ZKARA?= Date: Mon, 9 Mar 2026 23:24:41 +0300 Subject: [PATCH] Serialize mismatched args before enqueue Avoids invalid casts when the provided args are not of runtime type TArgs. The method now checks for a direct TArgs instance and calls EnqueueAsync directly; otherwise it serializes and deserializes the args via Serializer to produce a TArgs instance before enqueuing. This preserves the fast path for matching types while safely handling boxed or different runtime argument representations. --- .../Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs index 6345083926..33c41704f2 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs @@ -80,7 +80,13 @@ public class JobQueue : IJobQueue BackgroundJobPriority priority, TimeSpan? delay) { - return await EnqueueAsync((TArgs)args, priority, delay); + if (args is TArgs typedArgs) + { + return await EnqueueAsync(typedArgs, priority, delay); + } + + var serializedArgs = Serializer.Serialize(args); + return await EnqueueAsync((TArgs)Serializer.Deserialize(serializedArgs, typeof(TArgs)), priority, delay); } public virtual async Task EnqueueAsync(