1
votes

I'm building a .net core mvc application in vs code working with lucene.net and whenever I try to run this piece of code it throws an exception saying(and yes the index path does exist)

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Lucene.Net.Store.FSDirectory' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Lucene.Net.Util.Constants' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. at Lucene.Net.Support.AppSettings.Get(String key, String defValue) at Lucene.Net.Util.Constants..cctor() in d:\Lucene.Net\FullRepo\trunk\src\core\Util\Constants.cs:line 33 --- End of inner exception stack trace --- at Lucene.Net.Store.FSDirectory..cctor() in d:\Lucene.Net\FullRepo\trunk\src\core\Store\FSDirectory.cs:line 502 --- End of inner exception stack trace ---

if it helps the version of Lucene I'm running is

<PackageReference Include="Lucene.Net" Version="3.0.3"/>

SearchQuery()
     {
         indexPath = @"C:\MyDir";
         directory = FSDirectory.Open(new DirectoryInfo(indexPath));
         StandardAnalyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
         writer = new IndexWriter(directory,
         analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);

         dbContext = Program.context;

         addDocuments();
     }

and the above is the relevant piece of code

1

1 Answers

3
votes

"Lucene.Net" Version="3.0.3" is from 2012

does not support .net core

use 4.8

PM> Install-Package Lucene.Net -Pre

or

dotnet add package Lucene.Net --version 4.8.0-beta00005 

dotnet add package Lucene.Net.Analysis.Common --version 4.8.0-beta00005 

here code sample Lucene.Net.Demo.csproj

Ref