0
votes

I created an Azure Web API App which uses native 64 bit dlls. I am able to run the service locally without any issues. However, when I attempt to host it on Azure I get the below error.

There is a thread with a known issue about loading native DLLs inside of Azure apps. I followed the solution and created an XDT script to add the bin folder (D:\home\site\wwwroot\bin) to the PATH. Unfortunately that did not help.

I verified that my dlls are in the bin folder of the app using the Azure Portal Console. I also verified in Kudu that my app sees the updated path. I ensured that the application settings inside of the Azure Portal are set to 64bit. If I set the application settings back to the 32 bit mode it finds the dll and throws an incorrect format error instead, so it seems like that there is some issue referencing native 64 bit dlls inside of Azure.

I am getting the following error when I try to call my app:

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
1

1 Answers

2
votes

The issue was that I had compiled the DLLs as Debug and not Release which caused them to reference VCRUNTIME[...]D and MSVCP[...]D debug DLLs which are not available in Azure. Recompiling the DLLs in Release solved the issue.