{"record":{"id":"62d5c5d43045e116","repo":"litedb-org/LiteDB","slug":"value-cannot-be-null-parameter-repository","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'repository')","messagePattern":"Value cannot be null\\. \\(Parameter 'repository'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Vector/LiteRepositoryVectorExtensions.cs","lineNumber":35,"sourceCode":"        {\n            return Unwrap(repository).EnsureVectorIndex<T>(expression, options, collectionName);\n        }\n\n        public static bool EnsureIndex<T, K>(this ILiteRepository repository, Expression<Func<T, K>> keySelector, VectorIndexOptions options, string collectionName = null)\n        {\n            return Unwrap(repository).EnsureVectorIndex<T, K>(keySelector, options, collectionName);\n        }\n\n        public static bool EnsureIndex<T, K>(this ILiteRepository repository, string name, Expression<Func<T, K>> keySelector, VectorIndexOptions options, string collectionName = null)\n        {\n            return Unwrap(repository).EnsureVectorIndex<T, K>(name, keySelector, options, collectionName);\n        }\n\n        private static LiteRepository Unwrap(ILiteRepository repository)\n        {\n            if (repository is null)\n            {\n                throw new ArgumentNullException(nameof(repository));\n            }\n\n            if (repository is LiteRepository liteRepository)\n            {\n                return liteRepository;\n            }\n\n            throw new ArgumentException(\"Vector index operations require LiteDB's default repository implementation.\", nameof(repository));\n        }\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":47,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Vector/LiteRepositoryVectorExtensions.cs#L17-L47","documentation":"Thrown by Unwrap in LiteRepositoryVectorExtensions when the repository passed to a vector EnsureIndex extension is null. The extension forwards to the concrete LiteRepository to access the underlying collections and engine, so a null repository cannot proceed.","triggerScenarios":"Calling repo.EnsureVectorIndex<T,K>(...) on a null ILiteRepository; repository obtained from a scope that was already disposed; DI misconfiguration injecting null.","commonSituations":"Transient/scoped repository lifetimes resolving to null after disposal; test harnesses not initializing the repository; conditional instantiation branches skipping assignment.","solutions":["Confirm the repository is a live LiteRepository before calling the extension.","Fix DI registration so ILiteRepository resolves to a non-null instance for the scope.","Avoid holding repository references across dispose boundaries."],"exampleFix":"// before\nrepo.EnsureVectorIndex<MyDoc, float[]>(x => x.Embedding, opts);\n\n// after\nif (repo is null)\n    throw new InvalidOperationException(\"Repository is not available.\");\nrepo.EnsureVectorIndex<MyDoc, float[]>(x => x.Embedding, opts);","handlingStrategy":"validation","validationCode":"if (repo is null)\n    throw new InvalidOperationException(\"Repository is not available.\");\nrepo.EnsureVectorIndex<MyDoc, float[]>(x => x.Embedding, opts);","typeGuard":"static bool IsLiveRepository(ILiteRepository r) => r is not null;","tryCatchPattern":null,"preventionTips":["Verify DI scopes resolve a non-null repository.","Avoid holding repository references across disposal.","Initialize repositories eagerly in composition roots."],"tags":["argument-validation","vector","null-check","repository","extension-method"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}