第一次部署 ASP.NET web api,遇到'/'错误

Posted

技术标签:

【中文标题】第一次部署 ASP.NET web api,遇到\'/\'错误【英文标题】:First time deploying ASP.NET web api, ran into '/' error第一次部署 ASP.NET web api,遇到'/'错误 【发布时间】:2021-02-22 00:42:25 【问题描述】:

这是我第一次部署 ASP Web api。该 api 在 Debug/Release 部分运行顺利,但在第一次部署时出现错误。

libzkfpcsharp 是一个只支持 x86 的 dll。我将配置属性更改为 x86 以支持 dll,但仍然出现错误。有谁知道怎么处理?

Could not load file or assembly 'libzkfpcsharp' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'libzkfpcsharp' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'libzkfpcsharp' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace:


[BadImageFormatException: Could not load file or assembly 'libzkfpcsharp' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   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.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +232
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +113
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +23
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

[ConfigurationErrorsException: Could not load file or assembly 'libzkfpcsharp' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +767
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +256
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +58
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +287
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +69
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +137
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +854

[HttpException (0x80004005): Could not load file or assembly 'libzkfpcsharp' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +532
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +111
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +724

【问题讨论】:

【参考方案1】:

您还需要在 IIS 中更改 App.domain 以在 32 位模式下运行

【讨论】:

在哪里可以找到高级设置窗口?我发现的没有这样的选项。 打开 IIS –>转到当前服务器 –> 应用程序池 –>选择您的 32 位应用程序将在其下运行的应用程序池,单击高级设置,然后将启用 32 位应用程序设置为 True。 我正在将这个本地 api 交给一家公司。有没有更简单的方法来部署 web api? 你是如何部署web api的? Publish And Host ASP.NET Web API. 您需要询问您的提供商,了解如何让您的网站在 32 位应用程序池中运行

以上是关于第一次部署 ASP.NET web api,遇到'/'错误的主要内容,如果未能解决你的问题,请参考以下文章

ASP.NET Web API 应用程序在 IIS 7 上部署时提供 404

将 asp.net core web api 部署到 aws elastic beanstalk 时出现错误 404

将 asp.net core web api 部署到 IIS 7.5 时出现 500 错误

使用EF Database-First Application部署ASP.NET Web API

Asp.Net Web API 2第一课——入门

仅在 IIS 部署后的 Asp.net Web api 异常:名为“HelpPage_Default”的路由已在路由集合中