简体   繁体   English

C# Azure Function 和旧版 Z5884E40D596370BE5406F271AZAD9E39

[英]C# Azure Function and legacy DLL

I am trying to use Azure Function to do some calculations using a legacy.DLL我正在尝试使用 Azure Function 使用 legacy.DLL 进行一些计算

In my Azure function I have code like this and it works fine locally:在我的 Azure function 我有这样的代码,它在本地工作正常:

[DllImport("calculation.dll", ExactSpelling = false, CallingConvention = CallingConvention.StdCall, EntryPoint = "CreateItem")]
    private static extern int CreateItem([MarshalAs(UnmanagedType.LPStr)] string applicationName);

Running it in azure is get errors like this:在 azure 中运行它会得到如下错误:

[Error] Executed 'Calc' (Failed) Unable to load DLL 'C:\home\site\wwwroot\bin\runtimes\win7-x86\native\calculation.dll' or one of its dependencies: A dynamic link library (DLL) initialization routine failed. [错误] 执行 'Calc'(失败)无法加载 DLL 'C:\home\site\wwwroot\bin\runtimes\win7-x86\native\calculation.dll' 或其依赖项之一:动态链接库(DLL ) 初始化例程失败。 (0x8007045A) (0x8007045A)

Opening the DLL in Dependency walker I can see that it depends on:在 Dependency walker 中打开 DLL 我可以看到它取决于:

 c:\windows\system32\KERNEL32.DLL 
 c:\windows\system32\USER32.DLL
 c:\windows\system32\OLE32.DLL 
 c:\windows\system32\OLEAUT32.DLL

I tried copying the 4 dlls from my local computer and into the Azure Function without any luck.我尝试将 4 个 dll 从本地计算机复制到 Azure Function 没有任何运气。

Is this even the right direction to go trying the solve this?这甚至是 go 尝试解决这个问题的正确方向吗? Or is there something fundamental I am missing?还是我缺少一些基本的东西?

The whole point of Azure managed instances (and indeed, any cloud code-running service) is that everything your website/function/whatever needs to run is self-contained within the code package you upload to Azure. Azure 托管实例(实际上是任何云代码运行服务)的全部意义在于,您的网站/功能/需要运行的所有内容都包含在您上传到 Z3A580F1422036773F1F 的代码 package 中。 Code that tries to call out to arbitrary third-party DLLs, that themselves call out to other DLs, can never satisfy this requirement.尝试调用任意第三方 DLL 的代码,而这些 DLL 本身又调用了其他 DL,永远无法满足此要求。 (Not to mention that there's no guarantee whether the instance you're running on is even Windows to begin with). (更不用说无法保证您正在运行的实例是否甚至是 Windows 开始)。

The only way you could make this work is to provision a Windows VM on Azure, install your DLL there, and create a web API that invokes the DLL and returns the result; The only way you could make this work is to provision a Windows VM on Azure, install your DLL there, and create a web API that invokes the DLL and returns the result; then make your Azure Function call the web API.然后让你的 Azure Function 调用 web ZDB974238714CA8DE634A7CE1D083A1 But this is a massive amount of extra effort to work around the fact that P/Invoke really isn't a thing on Azure.但是,要解决 P/Invoke 在 Azure 上确实不存在的事实,需要付出大量额外的努力。

If you can't replace this DLL with managed code, you may want to reconsider trying to host this in the cloud.如果您无法使用托管代码替换此 DLL,您可能需要重新考虑尝试将其托管在云中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM