在 Azure Web Api 应用程序中引用本机 64 位 dll
Referencing native 64 bit dll in Azure Web Api App
我创建了一个使用本机 64 位 dll 的 Azure Web API 应用程序。我可以在本地 运行 服务,没有任何问题。但是,当我尝试在 Azure 上托管它时,出现以下错误。
有一个 thread 关于在 Azure 应用程序中加载本机 DLL 的已知问题。我按照解决方案创建了一个 XDT 脚本以将 bin 文件夹 (D:\home\site\wwwroot\bin) 添加到 PATH。不幸的是,这没有帮助。
我使用 Azure 门户控制台验证了我的 dll 位于应用程序的 bin 文件夹中。我还在 Kudu 中验证了我的应用程序看到了更新的路径。我确保 Azure 门户内的应用程序设置设置为 64 位。如果我将应用程序设置回 32 位模式,它会找到 dll 并抛出不正确的格式错误,因此在 Azure 中引用本机 64 位 dll 似乎存在一些问题。
我在尝试调用我的应用程序时遇到以下错误:
Server Error in '/' Application.
Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.
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.IO.FileNotFoundException: Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.
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.
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.]
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) +234
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +108
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +25
System.Reflection.Assembly.Load(String assemblyString) +34
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +49
[ConfigurationErrorsException: Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +772
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +259
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +163
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +230
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +76
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +343
System.Web.Compilation.BuildManager.ExecutePreAppStart() +176
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +734
[HttpException (0x80004005): Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +539
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +125
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +731
问题是我将 DLL 编译为 Debug 而不是 Release,这导致它们引用 VCRUNTIME[...]D 和 MSVCP[...]D 调试 DLL,这在 Azure 中不可用。重新编译 Release 中的 DLL 解决了这个问题。
我创建了一个使用本机 64 位 dll 的 Azure Web API 应用程序。我可以在本地 运行 服务,没有任何问题。但是,当我尝试在 Azure 上托管它时,出现以下错误。
有一个 thread 关于在 Azure 应用程序中加载本机 DLL 的已知问题。我按照解决方案创建了一个 XDT 脚本以将 bin 文件夹 (D:\home\site\wwwroot\bin) 添加到 PATH。不幸的是,这没有帮助。
我使用 Azure 门户控制台验证了我的 dll 位于应用程序的 bin 文件夹中。我还在 Kudu 中验证了我的应用程序看到了更新的路径。我确保 Azure 门户内的应用程序设置设置为 64 位。如果我将应用程序设置回 32 位模式,它会找到 dll 并抛出不正确的格式错误,因此在 Azure 中引用本机 64 位 dll 似乎存在一些问题。
我在尝试调用我的应用程序时遇到以下错误:
Server Error in '/' Application.
Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.
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.IO.FileNotFoundException: Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.
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.
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.]
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) +234
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +108
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +25
System.Reflection.Assembly.Load(String assemblyString) +34
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +49
[ConfigurationErrorsException: Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +772
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +259
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +163
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +230
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +76
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +343
System.Web.Compilation.BuildManager.ExecutePreAppStart() +176
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +734
[HttpException (0x80004005): Could not load file or assembly 'My64Bit.DLL' or one of its dependencies. The specified module could not be found.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +539
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +125
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +731
问题是我将 DLL 编译为 Debug 而不是 Release,这导致它们引用 VCRUNTIME[...]D 和 MSVCP[...]D 调试 DLL,这在 Azure 中不可用。重新编译 Release 中的 DLL 解决了这个问题。