首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用NHUnspell NuGet包时无法加载文件或程序集Hunspellx64.dll?

使用NHUnspell NuGet包时无法加载文件或程序集Hunspellx64.dll?
EN

Stack Overflow用户
提问于 2013-08-20 01:54:06
回答 1查看 2.5K关注 0票数 5

我有一个ASP.NET/MVC角色,它使用NHUnspell NuGet包。当我尝试运行它时,我会得到以下错误消息:

代码语言:javascript
复制
Could not load file or assembly 'Hunspellx64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.

这很奇怪,因为据我所知,我的Web角色项目不应该试图加载非托管Hunspellx64.dll。应该由托管的NHUnspell DLL处理。将该DLL复制到/bin角色的目录,作为构建步骤。

更新:,感谢托马斯关于WebActivator已经过时的评论,我能够解决这个问题。我正在复制我对他接受的答案的回复评论,以确保其他有此问题的人看到修复:

在这个错误发生之前,我已经让NHUnspell成功地工作了。失败的是用AttributeRouting安装了NuGet。AttributeRouting拖放旧版本的WebActivator (1.0.0.0)。不幸的是,当您执行更新操作时,NuGet不建议对它进行更新。您必须按照此网页的说明,通过Package控制台手动进行更新: http://www.nuget.org/packages/WebActivator

这里是在收到修复之前的原始帖子的其余部分:

我已经搜索了我的项目,寻找到Hunspellx64.dll 64. DLL的直接引用/链接。DLL包括我的NuGet包配置、packages.config、web.config、我的引用列表、原始项目文件等等。我找不到对该DLL的任何直接引用。我还可以在哪里查看,或者我还可以尝试阻止项目直接加载该非托管DLL?下面是ASP.NET错误转储:

代码语言:javascript
复制
[BadImageFormatException: Could not load file or assembly 'Hunspellx64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +102
   System.Reflection.Assembly.LoadFrom(String assemblyFile) +34
   WebActivator.PreApplicationStartCode.Start() in D:\Code\Bitbucket\WebActivator\WebActivator\PreApplicationStartCode.cs:11

[InvalidOperationException: The pre-application start initialization method Start on type WebActivator.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Hunspellx64.dll' or one of its dependencies. The module was expected to contain an assembly manifest..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): The pre-application start initialization method Start on type WebActivator.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Hunspellx64.dll' or one of its dependencies. The module was expected to contain an assembly manifest..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874568
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-20 06:19:20

WebActivator启动方法不处理bin文件夹中的非托管DLL。正如您在代码文件中看到的那样:https://bitbucket.org/dfowler/webactivator/src/4c558d93cf3a/WebActivator/PreApplicationStartCode.cs

代码语言:javascript
复制
 public static void Start() {
            lock (initLock) {
                if (!hasInited) {
                    // Go through all the bin assemblies
                    foreach (var assemblyFile in GetAssemblyFiles()) {
                        var assembly = Assembly.LoadFrom(assemblyFile);

                        // Go through all the PreApplicationStartMethodAttribute attributes
                        // Note that this is *our* attribute, not the System.Web namesake
                        foreach (PreApplicationStartMethodAttribute preStartAttrib in assembly.GetCustomAttributes(
                            typeof(PreApplicationStartMethodAttribute),
                            inherit: false)) {

                            // If it asks to be called after global.asax App_Start, keep track of the method. Otherwise call it now
                            if (preStartAttrib.CallAfterGlobalAppStart && HostingEnvironment.IsHosted) {
                                attribsToCallAfterStart.Add(preStartAttrib);
                            }
                            else {
                                // Invoke the method that the attribute points to
                                preStartAttrib.InvokeMethod();
                            }
                        }
                    }

Start()方法将所有DLL作为程序集加载以探测其PreApplicationStartMethodAttribute。这对于非托管DLL失败,因为没有程序集清单。

看起来你用的是树枝(dfolwler?)或过时版本的WebActivator,因为当前版本可以通过忽略程序集加载上的所有异常来处理此问题。

代码语言:javascript
复制
private static IEnumerable<Assembly> Assemblies
{
    get
    {
        if (_assemblies == null)
        {
            // Cache the list of relevant assemblies, since we need it for both Pre and Post
            _assemblies = new List<Assembly>();
            foreach (var assemblyFile in GetAssemblyFiles())
            {
                try
                {
                    // Ignore assemblies we can't load. They could be native, etc...
                    _assemblies.Add(Assembly.LoadFrom(assemblyFile));
                }
                catch
                {
                }
            }
        }

        return _assemblies;
    }
}

将WebActivator更新为最新版本。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18325799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档