{"record":{"id":"e8c6c418b99591d6","repo":"microsoft/autogen","slug":"invalid-queue-type-queuetype","errorCode":null,"errorMessage":"Invalid queue type: {_queueType}.","messagePattern":"Invalid queue type: (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/RuntimeGateway.Grpc/Services/Orleans/MessageRegistryQueue.cs","lineNumber":130,"sourceCode":"    }\n\n    private async Task AddOrUpdate(string topic, CloudEvent message)\n    {\n        var queue = GetQueue();\n        var list = queue.GetOrAdd(topic, _ => new());\n        list.Add(message);\n        queue.AddOrUpdate(topic, list, (_, _) => list);\n        await _stateManager.WriteStateAsync().ConfigureAwait(true);\n        _timestamps.Add(DateTime.UtcNow, topic);\n    }\n\n    private ConcurrentDictionary<string, List<CloudEvent>> GetQueue()\n    {\n        return _queueType switch\n        {\n            MessageRegistryGrain.QueueType.DeadLetterQueue => _state.State.DeadLetterQueue,\n            MessageRegistryGrain.QueueType.EventBuffer => _state.State.EventBuffer,\n            _ => throw new ArgumentException($\"Invalid queue type: {_queueType}.\")\n        };\n    }\n\n    public async Task RemoveMessageAfterDelayAsync(string topic, CloudEvent message, int delay)\n    {\n        await Task.Delay(delay);\n        await RemoveMessageAsync(topic, message);\n        _currentSize -= message.CalculateSize();\n    }\n}\n","sourceCodeStart":112,"sourceCodeEnd":141,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/RuntimeGateway.Grpc/Services/Orleans/MessageRegistryQueue.cs#L112-L141","documentation":"ArgumentException thrown by MessageRegistryQueue.GetQueue() when the grain's _queueType is neither QueueType.DeadLetterQueue nor QueueType.EventBuffer. The queue grain is constructed per queue type and switches on that value to pick the right state bucket; any other value (including an uncast int or an out-of-range enum) is rejected.","triggerScenarios":"Instantiating MessageRegistryQueue with an int cast to MessageRegistryGrain.QueueType that is not 0 or 1 (e.g. (QueueType)42); new queue kinds added to the enum without extending GetQueue's switch; deserialized grain state producing an unexpected enum value.","commonSituations":"Direct unit tests of the grain that pass arbitrary enum values; refactors that introduce a third queue type but forget this switch expression; enum reordering between serialized versions shifting numeric meanings.","solutions":["Construct the queue grain only with MessageRegistryGrain.QueueType.DeadLetterQueue or .EventBuffer.","If you add a new queue type, extend the switch in GetQueue() to map it to a state bucket (or throw a descriptive error naming the value).","Validate the enum at construction: if (!Enum.IsDefined(typeof(QueueType), value)) throw ... with the actual value."],"exampleFix":"// before\nvar queue = new MessageRegistryQueue((MessageRegistryGrain.QueueType)7, state, stateManager);\n\n// after\nvar queue = new MessageRegistryQueue(MessageRegistryGrain.QueueType.DeadLetterQueue, state, stateManager);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(MessageRegistryGrain.QueueType), queueType)\n    || queueType == (MessageRegistryGrain.QueueType)(-1))\n{\n    throw new ArgumentOutOfRangeException(nameof(queueType), queueType, \"QueueType must be DeadLetterQueue or EventBuffer\");\n}","typeGuard":"static bool IsKnownQueueType(MessageRegistryGrain.QueueType t) =>\n    t is MessageRegistryGrain.QueueType.DeadLetterQueue\n       or MessageRegistryGrain.QueueType.EventBuffer;","tryCatchPattern":"try { var queue = GetQueue(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid queue type\"))\n{\n    _logger.LogError(\"MessageRegistryQueue misconfigured with queue type {Type}.\", _queueType);\n    throw;\n}","preventionTips":["Only construct the grain with the two defined enum members.","When adding queue types, update GetQueue's switch in the same commit.","Validate enum values at construction boundaries in tests."],"tags":["dotnet","orleans","grain","enum"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}