在Azure Web Api App中引用原生64位dll

问题描述:

我创建了一个使用原生64位dll的Azure Web API应用程序。我能够在没有任何问题的情况下在本地运行服务。但是,当我尝试在Azure上托管它时,出现以下错误。在Azure Web Api App中引用原生64位dll

有一个thread与一个已知的问题有关在Azure应用程序内加载本机DLL。我按照解决方案创建了一个XDT脚本来将bin文件夹(D:\ home \ site \ wwwroot \ bin)添加到PATH中。不幸的是,这并没有帮助。

我使用Azure Portal Console验证了我的dll位于应用程序的bin文件夹中。我也在Kudu验证我的应用程序看到更新的路径。我确保Azure Portal内的应用程序设置设置为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的调试和不释放造成他们引用VCRUNTIME [...] D和MSVCP D调试DLL,这些DLL在Azure中不可用。重新编译Release中的DLL解决了这个问题。