exception in c# exe using NHUspell

147 views Asked by At

I have a problem with my project.

This is a project for my university.

I decided to add HNUSpell from nuget package in order to check spelling It works well in code but unfortunately whn I make an .exe from it I face with this Exception: enter image description here

here is code:

     using (Hunspell hunspell = new Hunspell("en_US.aff", "fa.dic"))
             {
                 string[] lines = System.IO.File.ReadAllLines("New Text Document (2).txt");
                 foreach (var line in lines)
                 {
                     line.Replace(" " , string.Empty);
                     hunspell.Add(line);
                 }

      List<string> suggestions = hunspell.Suggest(myInput);
                 foreach (string suggestion in suggestions)
                 {
                     //Do something
                 }

I really got confused and don't what should I do.

Can anyone please help me?

thanks in advance

1

There are 1 answers

0
Jan Köhler On

In the first line of your code snippet you specify the path to the aff file:

using (Hunspell hunspell = new Hunspell("en_US.aff", "fa.dic"))

You provide a relative path "en_US.aff". When you run your program the exception occurs, because the file can't be found nearby.

What you could do is specifying a absolute path instead of a relative one:

new Hunspell("C:\somePath\en_US.aff", "C:\somePath\fa.dic"))