diff --git a/src/Examine/LuceneEngine/Providers/LuceneSearcher.cs b/src/Examine/LuceneEngine/Providers/LuceneSearcher.cs index ceb044582..2ccaaa259 100644 --- a/src/Examine/LuceneEngine/Providers/LuceneSearcher.cs +++ b/src/Examine/LuceneEngine/Providers/LuceneSearcher.cs @@ -89,6 +89,9 @@ public override Searcher GetLuceneSearcher() public override ISearchContext GetSearchContext() { + var searcher = GetLuceneSearcher(); + if (searcher == null) + throw new InvalidOperationException($"Cannot create a {typeof(ISearchContext)}, the {Name} index either doesn't exist or the {typeof(LuceneSearcher)} has been disposed"); return new SearchContext(FieldValueTypeCollection, GetLuceneSearcher()); } @@ -181,6 +184,7 @@ private bool ValidateSearcher() { //can't proceed if there's no index if (!IndexExistsImpl()) return false; + if (_disposed) return false; //TODO: Would be nicer if this used LazyInitializer instead of double check locking diff --git a/src/Examine/LuceneEngine/Search/SearchContext.cs b/src/Examine/LuceneEngine/Search/SearchContext.cs index f19976a2c..0dd2403d5 100644 --- a/src/Examine/LuceneEngine/Search/SearchContext.cs +++ b/src/Examine/LuceneEngine/Search/SearchContext.cs @@ -10,8 +10,8 @@ public class SearchContext : ISearchContext public SearchContext(FieldValueTypeCollection fieldValueTypeCollection, Searcher searcher) { - _fieldValueTypeCollection = fieldValueTypeCollection; - Searcher = searcher; + _fieldValueTypeCollection = fieldValueTypeCollection ?? throw new System.ArgumentNullException(nameof(fieldValueTypeCollection)); + Searcher = searcher ?? throw new System.ArgumentNullException(nameof(searcher)); } public Searcher Searcher { get; }