Failed to load Hunspellx64.dll file or assembly when using NHUnspell NuGet?

I have an ASP.NET/MVC web role using the NHUnspell NuGet package. When I try to start it, I get 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. 

This is strange because, as far as I know, my web role project should not load the unmanaged Hunspellx64.dll file at all. This must be handled by the NHUnspell Managed DLL. This DLL is copied to the / bin directory of the web role as a build step.

UPDATE: Thanks to Thomas comment on deprecating WebActivator, I was able to fix this problem. I duplicate my answer to my accepted answer to make sure that others who have this problem see a fix:

I had NHUnspell, which worked successfully before this error started happening. What broke was installing AttributeRouting with NuGet. AttributeRouting drags the old version of WebActivator (1.0.0.0). Unfortunately, NuGet does not offer updates for it when you perform an update operation. You need to manually perform the update through the package manager console in accordance with the instructions on this web page:

http://www.nuget.org/packages/WebActivator

Here is the rest of the original message before the fix was received:

I looked at my project for direct links / links to Hunspellx64.dll, including the configuration of NuGet packages, packages.config, web.config, a list of links, the project source file, etc. I can not find direct links to this dll. Where else can I look or what else can I try to stop my project from trying to load this unmanaged DLL directly? Here is the dump of the ASP.NET error:

 [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 
+4
source share
1 answer

The WebActivator startup method does not process unmanaged DLLs in the bin folder. As you can see in the code file: https://bitbucket.org/dfowler/webactivator/src/4c558d93cf3a/WebActivator/PreApplicationStartCode.cs

  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(); } } } 

The Start () method loads all DLLs as assemblies to test their PreApplicationStartMethodAttribute. This fails for the unmanaged DLL because there is no assembly manifest.

It looks like you're using a branch (dfolwler?) Or an outdated version of WebActivator, because the current version can handle this, ignoring all exceptions when loading the assembly.

 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; } } 

Update WebActivator to the latest version.

+5
source

Source: https://habr.com/ru/post/1497900/


All Articles