在Azure Web Api App中引用本机64位dll

时间:2016-11-04 02:18:00

标签: .net azure dll 64-bit azure-web-app-service

我创建了一个使用本机64位dll的Azure Web API应用程序。我可以在本地运行该服务,没有任何问题。但是,当我尝试在Azure上托管它时,我得到以下错误。

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

我使用Azure Portal Console验证了我的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

1 个答案:

答案 0 :(得分:1)

问题是我已经将DLL编译为Debug而不是Release,导致它们引用了Azure中不可用的VCRUNTIME D和MSVCP D调试DLL。在Release中重新编译DLL解决了这个问题。