Hi,
I am using NHunspell on a virtual dedicated server. I am starting/creating the spell check objects as such:
static SpellEngine spellEngine;
static public SpellEngine SpellEngine { get { return spellEngine; } }
void Application_Start(object sender, EventArgs e)
{
try
{
string dictionaryPath = Server.MapPath("Bin") + "\\";
Hunspell.NativeDllPath = dictionaryPath;
spellEngine = new SpellEngine();
LanguageConfig enConfig = new LanguageConfig();
enConfig.LanguageCode = "en";
enConfig.HunspellAffFile = dictionaryPath + "en_us.aff";
enConfig.HunspellDictFile = dictionaryPath + "en_us.dic";
enConfig.HunspellKey = "";
spellEngine.AddLanguage(enConfig);
LanguageConfig esConfig = new LanguageConfig();
esConfig.LanguageCode = "es";
esConfig.HunspellAffFile = dictionaryPath + "es_ES.aff";
esConfig.HunspellDictFile = dictionaryPath + "es_ES.dic";
esConfig.HunspellKey = "";
spellEngine.AddLanguage(esConfig);
LanguageConfig frConfig = new LanguageConfig();
frConfig.LanguageCode = "fr";
frConfig.HunspellAffFile = dictionaryPath + "fr-moderne.aff";
frConfig.HunspellDictFile = dictionaryPath + "fr-moderne.dic";
frConfig.HunspellKey = "";
spellEngine.AddLanguage(frConfig);
LanguageConfig deConfig = new LanguageConfig();
deConfig.LanguageCode = "de";
deConfig.HunspellAffFile = dictionaryPath + "de_DE_igerman98.aff";
deConfig.HunspellDictFile = dictionaryPath + "de_DE_igerman98.dic";
deConfig.HunspellKey = "";
spellEngine.AddLanguage(deConfig);
}
catch (Exception)
{
if (spellEngine != null)
spellEngine.Dispose();
}
}
I start getting this error after some time (minutes) of testing the server:
System.NullReferenceException: Object reference not set to an instance of an object.
It works for a while though.
Calling the spell checker object seems to be creating this:
if (Global.SpellEngine[Lang].Spell(WordToCheck) != true)//Incorrect spelling
{
...
My question is why does the SpellEngine object seem to get disposed of or is null after a while? I thought that Application_Start would create the object for the life of the web application?
Can anyone tell me what troubleshooting direction I should take? How can I determine what is happening to the SpellEngine object?
Also, how/where can I (or should I have to) recreate this object if it is null?
Another thing...sometimes it will work for a while then it will crash (Object null) but then after some time, it will start working again.
Thanks