{"record":{"id":"ee0c93cf503afbce","repo":"litedb-org/LiteDB","slug":"engine","errorCode":null,"errorMessage":"engine","messagePattern":"engine","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Database/LiteDatabase.cs","lineNumber":98,"sourceCode":"                    // Without a dedicated log stream the WAL lives purely in memory; force\n                    // checkpointing to ensure commits reach the underlying data stream.\n                    var originalCheckpointSize = _engine.Pragma(Pragmas.CHECKPOINT);\n\n                    if (originalCheckpointSize != 1)\n                    {\n                        _engine.Pragma(Pragmas.CHECKPOINT, 1);\n                        _checkpointOverride = originalCheckpointSize;\n                    }\n                }\n            }\n        }\n\n        /// <summary>\n        /// Start LiteDB database using a pre-exiting engine. When LiteDatabase instance dispose engine instance will be disposed too\n        /// </summary>\n        public LiteDatabase(ILiteEngine engine, BsonMapper mapper = null, bool disposeOnClose = true)\n        {\n            _engine = engine ?? throw new ArgumentNullException(nameof(engine));\n            _mapper = mapper ?? BsonMapper.Global;\n            _disposeOnClose = disposeOnClose;\n        }\n\n        #endregion\n\n        #region Collections\n\n        /// <summary>\n        /// Get a collection using an entity class as strong typed document. If collection does not exist, create a new one.\n        /// </summary>\n        /// <param name=\"name\">Collection name (case insensitive)</param>\n        /// <param name=\"autoId\">Define autoId data type (when object contains no id field)</param>\n        public ILiteCollection<T> GetCollection<T>(string name, BsonAutoId autoId = BsonAutoId.ObjectId)\n        {\n            return new LiteCollection<T>(name, autoId, _engine, _mapper);\n        }\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Database/LiteDatabase.cs#L80-L116","documentation":"ArgumentNullException thrown by the LiteDatabase(ILiteEngine, ...) constructor when engine is null. This overload wraps a pre-existing engine instance (e.g. a shared or mocked ILiteEngine); a null engine leaves LiteDatabase with nothing to delegate to, so it is rejected immediately.","triggerScenarios":"Constructing new LiteDatabase((ILiteEngine)null); a DI container resolving ILiteEngine to null; passing a factory result that returned null; wiring a mock engine in tests but forgetting to instantiate it.","commonSituations":"Dependency injection registration missing for ILiteEngine; a factory/orchestrator returning null on misconfiguration; test setup forgetting to create the mock engine.","solutions":["Provide a real or mock ILiteEngine, e.g. new LiteDatabase(new LiteEngine(settings)).","Register ILiteEngine in the DI container so resolution succeeds.","Null-check the engine at the call site with a descriptive error before constructing LiteDatabase."],"exampleFix":"// before\nvar db = new LiteDatabase((ILiteEngine)null);\n\n// after\nvar engine = engineFactory.Create() ?? throw new InvalidOperationException(\"Engine factory returned null.\");\nvar db = new LiteDatabase(engine);","handlingStrategy":"validation","validationCode":"ILiteEngine engine = engineFactory.Create()\n    ?? throw new InvalidOperationException(\"Engine factory returned null; check DI registration.\");\nvar db = new LiteDatabase(engine);","typeGuard":"static bool HasEngine(ILiteEngine engine) => engine != null;","tryCatchPattern":null,"preventionTips":["Register ILiteEngine in the DI container.","Make engine factories throw with context instead of returning null.","Null-check the engine at the composition root before wrapping it."],"tags":["constructor","engine","argumentnull","di"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}