{"record":{"id":"84bcd5c1d36ce9dd","repo":"litedb-org/LiteDB","slug":"stream","errorCode":null,"errorMessage":"stream","messagePattern":"stream","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Database/LiteDatabase.cs","lineNumber":63,"sourceCode":"        {\n            if (connectionString == null) throw new ArgumentNullException(nameof(connectionString));\n\n            _engine = connectionString.CreateEngine();\n            _mapper = mapper ?? BsonMapper.Global;\n            _disposeOnClose = true;\n        }\n\n        /// <summary>\n        /// Starts LiteDB database using a generic Stream implementation (mostly MemoryStream).\n        /// </summary>\n        /// <param name=\"stream\">DataStream reference </param>\n        /// <param name=\"mapper\">BsonMapper mapper reference</param>\n        /// <param name=\"logStream\">LogStream reference </param>\n        public LiteDatabase(Stream stream, BsonMapper mapper = null, Stream logStream = null)\n        {\n            var settings = new EngineSettings\n            {\n                DataStream = stream ?? throw new ArgumentNullException(nameof(stream)),\n                LogStream = logStream\n            };\n\n            _engine = new LiteEngine(settings);\n            _mapper = mapper ?? BsonMapper.Global;\n            _disposeOnClose = true;\n\n            if (logStream == null && stream is not MemoryStream)\n            {\n                if (!stream.CanWrite)\n                {\n                    // Read-only streams cannot participate in eager checkpointing because the process\n                    // writes pages back to the underlying data stream immediately.\n                }\n                else\n                {\n                    // Without a dedicated log stream the WAL lives purely in memory; force\n                    // checkpointing to ensure commits reach the underlying data stream.","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Database/LiteDatabase.cs#L45-L81","documentation":"ArgumentNullException thrown by the LiteDatabase(Stream, ...) constructor when stream is null. The stream is the backing data store (often a MemoryStream), assigned directly to EngineSettings.DataStream; a null stream cannot back an engine so it is rejected before construction.","triggerScenarios":"Constructing new LiteDatabase((Stream)null); a factory method returning null for the stream; in-memory testing helper that forgot to allocate the MemoryStream.","commonSituations":"Unit test scaffolding that passes null intending to mean 'in-memory'; a stream provider returning null on error without throwing; deserialization/DI supplying null.","solutions":["Pass a real stream, e.g. new LiteDatabase(new MemoryStream()).","Fix the stream provider to throw a descriptive error instead of returning null.","Add a null check upstream of the constructor with a clear configuration message."],"exampleFix":"// before\nvar db = new LiteDatabase((Stream)null);\n\n// after\nvar db = new LiteDatabase(new MemoryStream());\n// or\nvar stream = streamFactory.Create() ?? throw new InvalidOperationException(\"Stream factory returned null.\");\nvar db = new LiteDatabase(stream);","handlingStrategy":"validation","validationCode":"Stream stream = streamFactory.Create()\n    ?? throw new InvalidOperationException(\"Stream factory returned null.\");\nvar db = new LiteDatabase(stream);","typeGuard":"static bool IsUsableStream(Stream s) => s != null && (s.CanRead || s.CanWrite);","tryCatchPattern":null,"preventionTips":["Use new MemoryStream() for in-memory databases rather than null.","Make stream providers throw on failure instead of returning null.","Null-check stream sources at the boundary before constructing LiteDatabase."],"tags":["constructor","stream","argumentnull"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}