如何解决Hunspell Intel 32位DLL未找到的异常?

6

我使用以下代码进行拼写检查。

当我运行它时,我遇到了一个DLL文件未找到的异常:

"Hunspell Intel 32Bit DLL not found: C:\project\splee\Hunspellx86.dll".

代码片段:

using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic")) 
    { 
        bool correct = hunspell.Spell("Recommendation"); 
        var suggestions = hunspell.Suggest("Recommendation"); 
        foreach (string suggestion in suggestions) 
        { 
            Console.WriteLine("Suggestion is: " + suggestion); 
        } 
    } 

    // Hyphen 
    using (Hyphen hyphen = new Hyphen("hyph_en_us.dic")) 
    { 
        var hyphenated = hyphen.Hyphenate("Recommendation"); 
    } 


    using (MyThes thes = new MyThes("th_en_us_new.idx", "th_en_us_new.dat")) 
    { 
        using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic")) 
        { 
            ThesResult tr = thes.Lookup("cars", hunspell); 
            foreach (ThesMeaning meaning in tr.Meanings) 
            { 
                Console.WriteLine("  Meaning: " + meaning.Description); 
                foreach (string synonym in meaning.Synonyms) 
                { 
                    Console.WriteLine("    Synonym: " + synonym); 

                } 
            } 
        } 

我在项目中引用了 Hunspell.dll,出了什么问题?

5个回答

5
您需要在托管的NHunspell.dll旁边包含本地的Hunspellx86.dll
我是按照以下步骤进行的:
  1. 引用了NHunspell
  2. 设置了“复制到本地”属性。
  3. NHunspellx86.dll包含到我的项目中。
  4. 将“复制到输出目录”属性设置为“仅当较新时复制”。
这样可以确保本地的Hunspell.dll已经就位。

这只是在验证 NHunspellx** DLL 不在正确位置(bin 文件夹中)的情况下才是有用的解决方案。在我的情况下,DLL 明确地放置在正确的位置。 - Lisa

3
我使用 NHunspell v0.9.4 在两个不同的情境下重现了此错误。似乎,在加载相关未管理的 Hunspellx**.dll 的过程中可能会出现一系列问题,而 NHunspell 会显示此错误消息。
我发现第一个原因是,如果运行 Web 应用程序的特定 IIS 应用程序池没有启用 32 位应用程序,则会出现这种情况。当然,如果您在 64 位机器上运行 32 位 Web 应用程序,则仅与此相关。
我发现第二个原因是,如果 IIS 进程用户没有适当的权限来读取包含 Hunspellx**.dll 的文件夹,则会出现此错误。IIS 用户(名为类似于 MACHINENAME\IIS_IUSRS 的组)必须具有读取和执行 Web 应用程序执行目录(以及 bin 子文件夹)中的每个文件的权限。

感谢您的提示 - 我也遇到了同样的问题,但是IIS进程需要对该目录具有读取权限。然而,对于我们来说,更改32位Web应用程序并没有解决这个问题。 - leon.io

1

在解决方案资源管理器中右键单击NHunspell.DLL时,请确保将“复制本地设置”设置为“始终复制”。


1
我能够在VB.net 2010中解决这个问题,假设类似的操作可以在C#和后续版本的VB.net中完成:
  1. 在“解决方案资源管理器”中双击“我的项目”。
  2. 点击“查看应用程序事件”按钮。
  3. 添加一个应用程序启动事件,如下所示:
 Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
     Hunspell.NativeDllPath = "D:\VB.net\_system\hunspell\dll\" '(replace path with folder containing Hunspellx86.dll)
 End Sub

我相信你也可以将Hunspellx86.dll放在包含应用程序.exe文件的文件夹中。


0

在生产环境中,我遇到了这个问题,因为未管理的DLL版本略低于ASP.Net项目构建的版本。

具体来说,FusLogVw显示:

LOG: Assembly download was successful. Attempting setup of file: C:\ThePath\Hunspellx64.dll
LOG: Entering download cache setup phase.
ERR: Error extracting manifest import from file (hr = 0x80131018).
ERR: Setup failed with hr = 0x80131018.
ERR: Failed to complete setup of assembly (hr = 0x80131018). Probing terminated.

更新到正确版本的非托管 DLL 解决了该问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接