title: Lucene - AlreadyClosedException: this IndexReader is closed
body: <p>I am new to Lucene, so please bear with me.</p>
  
  <p>I've a class LuceneUtility which my application uses to call RequestIndexSearcher() to acquire indexSearcher object and to perform all search.
  Every time while return indexSearcher object I'm updating index (if anything needs to be updated) and recreated IndexSearcher object to reflect the new update (if there is any new update) but sometimes I'm getting AlreadyClosedException: this IndexReader is closed.</p>
  
  <pre><code>public class LuceneUtility
  {
      private static IndexSearcher _searcher;
      private static Directory _directory;
      private static Lazy&lt;IndexWriter&gt; _writer = new Lazy&lt;IndexWriter&gt;(() =&gt; new IndexWriter(_directory, new KeywordLowerCaseAnalyser(), IndexWriter.MaxFieldLength.UNLIMITED));
  
      private static Object lock_Lucene = new object();
  
      //this private constructor makes it a singleton now.
      private LuceneUtility() { }
  
      //Static constructor, opening the directory once for all.
      static LuceneUtility()
      {
          string s ="Path of lucene Index";
          _directory = FSDirectory.Open(s);
      }
  
      public static IndexSearcher IndexSearcher
      {
          get
          {
              if (_searcher == null)
              {
                  InitializeSearcher();
              }
              else if (!_searcher.IndexReader.IsCurrent())
              {
  
                  _searcher.Dispose();
                  InitializeSearcher();
              }
  
              return _searcher;
          }
      }
  
      public static IndexWriter IndexWriter
      {
          get
          {               
              return _writer.Value;
          }
      }
  
      private static void InitializeSearcher()
      {
          _searcher = new IndexSearcher(_directory, false);
  
      }
  
      public static IndexSearcher RequestIndexSearcher()
      {
  
          lock (lock_Lucene)
          {
              PerformIndexUpdation();
          }
  
          return IndexSearcher;
      }
      /// &lt;summary&gt;
      /// Performs Lucene Index Updation
      /// &lt;/summary&gt;
      private static void PerformIndexUpdation()
      {
  
       // Performs Index Updation 
      }
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>     AlreadyClosedException: this IndexReader is closed
      Lucene.Net.Index.IndexReader.EnsureOpen()
     at Lucene.Net.Index.DirectoryReader.IsCurrent()
     at LuceneOperation.LuceneUtility.get_IndexSearcher()
     at LuceneOperation.LuceneUtility.RequestIndexSearcher()
  </code></pre>
  
  <p>So... What's the deal here...? What am I doing wrong ?</p>
  
  <p>Many thanks in advance! :)</p>