{"record":{"id":"a01e0525ca06126f","repo":"dotnet/machinelearning","slug":"engine-parameter-engine","errorCode":null,"errorMessage":"engine (Parameter 'engine')","messagePattern":"engine \\(Parameter 'engine'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Extensions.ML/PoolLoader.cs","lineNumber":83,"sourceCode":"                throw new ObjectDisposedException(nameof(PoolLoader<TData, TPrediction>));\n            }\n\n            var engine = pool.Get();\n\n            _rentedEngines.Remove(engine);\n            _rentedEngines.Add(engine, pool);\n            return engine;\n        }\n\n        /// <summary>\n        /// Returns an engine to the generation it was rented from. If that generation has already\n        /// been disposed by a hot-swap, the pool disposes the engine instead of retaining it.\n        /// </summary>\n        public void Return(PredictionEngine<TData, TPrediction> engine)\n        {\n            if (engine == null)\n            {\n                throw new ArgumentNullException(nameof(engine));\n            }\n\n            if (_rentedEngines.TryGetValue(engine, out var origin))\n            {\n                _rentedEngines.Remove(engine);\n                origin.Return(engine);\n            }\n            else\n            {\n                engine.Dispose();\n            }\n        }\n\n        private void LoadPool()\n        {\n            if (Volatile.Read(ref _disposed) != 0)\n            {\n                return;","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Extensions.ML/PoolLoader.cs#L65-L101","documentation":"ArgumentNullException in PoolLoader<TData,TPrediction>.Return: the engine parameter is null. Return must put a previously rented PredictionEngine back into its originating pool (or dispose it if that generation was hot-swapped), so a null reference cannot be identified with any rental and is rejected immediately. The message names 'engine' as the faulty parameter.","triggerScenarios":"Calling ReturnPredictionEngine / PoolLoader.Return(null), typically when a variable was never assigned or a Get() failed earlier.","commonSituations":"Code paths where engine creation failed but Return is still called in a finally block without a null check.","solutions":["Guard for null before calling Return","Only return engines that were successfully rented from Get()"],"exampleFix":"// before\npool.ReturnPredictionEngine(engine); // engine may be null\n// after\nif (engine != null) pool.ReturnPredictionEngine(engine);","handlingStrategy":"type-guard","validationCode":"if (engine is null) throw new InvalidOperationException(\"No engine to return\");","typeGuard":"bool CanReturn(PredictionEngine<TData,TPred> e) => e != null;","tryCatchPattern":"null // prevent by null-checking before Return; no need to catch ArgumentNullException","preventionTips":["Null-check in finally blocks before returning engines","Only return engines obtained from Get()"],"tags":["null-argument","pooling"],"backgroundTag":"null-argument","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}