C# 使用NHUnspell NuGet包时无法加载文件或程序集X64.dll?

C# 使用NHUnspell NuGet包时无法加载文件或程序集X64.dll?,c#,asp.net,dll,unmanaged,nhunspell,C#,Asp.net,Dll,Unmanaged,Nhunspell,我有一个ASP.NET/MVC Web角色,正在使用NHUnspell NuGet包。当我尝试运行它时,会收到以下错误消息: 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。这

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

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作为构建步骤复制到Web角色的/bin目录

更新:多亏了托马斯关于WebActivator过时的评论,我才得以解决这个问题。我将我的回复意见复制到他接受的答案上,以确保其他有此问题的人看到解决方案:

在这个错误开始之前,我已经让NHUnspell成功地工作了 发生。是什么打破了这一切 努吉。在旧版本的WebActivator中拖动属性 (1.0.0.0). 不幸的是,NuGet不建议在以下情况下对其进行更新: 执行更新操作。您必须手动执行更新 按照本网页的说明,通过Package Manager控制台:

以下是收到修复之前原始帖子的其余部分:

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

[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

WebActivator启动方法不处理bin文件夹中的非托管DLL。 正如您在代码文件中看到的:

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

看起来您正在使用分支(dfolwler?)或WebActivator的过时版本,因为当前版本可以通过忽略程序集加载时的所有异常来处理此问题

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;
    }
}
私有静态IEnumerable程序集
{
得到
{
如果(_assemblies==null)
{
//缓存相关程序集的列表,因为我们在Pre和Post中都需要它
_assemblies=新列表();
foreach(GetAssemblyFiles()中的var assemblyFile)
{
尝试
{
//忽略无法加载的程序集。它们可能是本机程序集,等等。。。
_Add(Assembly.LoadFrom(assemblyFile));
}
抓住
{
}
}
}
返回组件;
}
}

将WebActivator更新至最新版本。

就是这样做的。在这个错误开始发生之前,我已经让NHUnspell成功地工作了。破坏一切的是用NuGet安装AttributeRouting。在旧版本的WebActivator(1.0.0.0)中拖动属性。不幸的是,在执行更新操作时,NuGet不建议对其进行更新。您必须按照此网页的说明,通过Package Manager控制台手动执行更新:WebActivator已被弃用,取而代之的是WebActivatorEx;希望有一些NuGet技巧可以让WebActivatorEx满足WebActivator的依赖性要求,或者每个需要它的人都转向了WebActivatorEx
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;
    }
}