{"record":{"id":"7696a892afedfa20","repo":"dotnet/machinelearning","slug":"you-need-to-configure-a-default-not-named-model","errorCode":null,"errorMessage":"You need to configure a default, not named, model before you use this method.","messagePattern":"You need to configure a default, not named, model before you use this method\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Extensions.ML/PredictionEnginePool.cs","lineNumber":107,"sourceCode":"        {\n            if (Volatile.Read(ref _disposed) != 0)\n            {\n                throw new ObjectDisposedException(nameof(PredictionEnginePool<TData, TPrediction>));\n            }\n\n            if (_namedPools.TryGetValue(modelName, out var existingPool))\n            {\n                return existingPool.Get();\n            }\n\n            //This is the case where someone has used string.Empty to get the default model.\n            //We can throw all the time, but it seems reasonable that we would just do what\n            //they are expecting if they know that an empty string means default.\n            if (string.IsNullOrEmpty(modelName))\n            {\n                if (_defaultEnginePool == null)\n                {\n                    throw new ArgumentException(\"You need to configure a default, not named, model before you use this method.\");\n                }\n\n                return _defaultEnginePool.Get();\n            }\n\n            var pool = AddPool(modelName);\n            return pool.Get();\n        }\n\n        private PoolLoader<TData, TPrediction> AddPool(string modelName)\n        {\n            //Here we are in the world of named models where the model hasn't been built yet.\n            var options = _predictionEngineOptions.Create(modelName);\n            var pool = new PoolLoader<TData, TPrediction>(_serviceProvider, options);\n            pool = _namedPools.GetOrAdd(modelName, pool);\n            return pool;\n        }\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Extensions.ML/PredictionEnginePool.cs#L89-L125","documentation":"GetPredictionEngine treats an empty/null modelName as 'the default model'. If no default pool was configured via options (only named models were registered), _defaultEnginePool is null and this ArgumentException is thrown.","triggerScenarios":"Calling GetPredictionEngine() or GetPredictionEngine(\"\") when registration only used AddPredictionEnginePool<TData,TPrediction>().WithName(\"x\") style named models and no default model/options were supplied.","commonSituations":"Forgetting to configure ModelName/default in AddPredictionEnginePool options; passing an unset/empty string variable as the model name.","solutions":["Configure the default model in options (set the model name/file in AddPredictionEnginePool<TData,TPrediction>().SetModelFile(...) without a name)","Pass a valid non-empty registered model name","Validate modelName is non-empty before calling"],"exampleFix":"// before\nservices.AddPredictionEnginePool<MData,Pred>().FromFile(\"modelA\", \"a.zip\");\nvar eng = pool.GetPredictionEngine(); // throws: no default\n// after\nservices.AddPredictionEnginePool<MData,Pred>().FromFile(\"modelA\", \"a.zip\");\nvar eng = pool.GetPredictionEngine(\"modelA\"); // or register a default model","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(modelName)) throw new InvalidOperationException(\"Configure a default model or pass a registered name\");","typeGuard":"bool HasDefault<TData,TPred>(PredictionEnginePool<TData,TPred> p) { try { p.GetPredictionEngine(); return true; } catch (ArgumentException) { return false; } } // prefer validating config at startup","tryCatchPattern":"try { var e = pool.GetPredictionEngine(modelName); } catch (ArgumentException ex) when (ex.Message.Contains(\"configure a default\")) { // fall back to a named model or fix registration\n    throw; }","preventionTips":["Always configure the default model when callers use the parameterless overload","Centralize model names in constants","Validate pool registration in integration tests"],"tags":["configuration","argument","default-model"],"backgroundTag":"missing-required-config","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"}