簡體   English   中英

在 Azure Linux App Service 上使用 p/invoke 時出錯 .NET 6.0 和自定義本機共享庫“沒有這樣的文件或目錄”

[英]Error using p/invoke on Azure Linux App Service with .NET 6.0 and custom native shared library "no such file or directory"

我在 ASP.NET Core .NET 6 應用程序中使用本機代碼 DLL。 I have compiled both a DLL for windows and a.so for Linux. I invoke it with the DLLImport attribute and the .NET loader is normally able to find the file both on Windows and Linux. The native code DLL is copied into the application output directory與編譯后的 .NET 代碼的 rest 一起。

該應用程序既可以在 Windows 上運行,也可以在虛擬機中的 Ubuntu 上進行測試安裝。 但是,在 Azure App Service (Linux) 上運行時出現錯誤:

無法加載共享庫“mylib”或其依賴項之一。 為了幫助診斷加載問題,考慮設置 LD_DEBUG 環境變量:libmylib: cannot open shared object file: No such file or directory

該應用程序通過 Azure DevOps 管道部署,使用這些發布 arguments:

arguments: '--配置 $(BuildConfiguration) -r linux-x64 --self-contained true --output $(Build.ArtifactStagingDirectory)'

Azure DevOps Pipelines 能夠為應用程序運行單元測試,包括那些調用本機庫的應用程序。

我使用 SSL 和 Bash 檢查 Azure App Service 中的文件系統,我可以看到 libmylib.so 與編譯后的 .NET 代碼的 rest 一起出現在目錄中。

我嘗試將它復制到 /usr/local/lib ,但它仍然沒有用。

在Azure App Service中如何調用該文件成功? 我會因為缺少其他依賴項而收到錯誤嗎?

你可以登錄kudu站點,站點url應該是這樣的:

https://your_sitename.scm.azurewebsites.net/newui

然后點擊webssh,然后運行命令進行安裝。

apt-get install libgomp1

如果它不起作用,您可以運行apt-get updateapt-get install g++ 更多詳細信息,請查看我測試的測試步驟

我也有一個解決方法:

您可以使用 docker 容器創建 webapp。 您只需確保它在您當地運行良好即可。

在此處輸入圖像描述

這里的問題是官方 .NET 6.0 運行時容器 mcr.microsoft.com/do.net/as.net:6.0 當前運行 debian buster 並且 glibc 的版本是 2.28,這對於我的依賴項之一來說太舊了。

.NET 7.0 運行時容器可以,但我還沒有嘗試升級。

我找到的解決方案是下載 debian buster 並重新編譯我的共享庫。 這現在與安裝 libgomp1 一起工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM