问题描述
我们在 Linux 主机上运行了一个 Azure Function。
我们的应用程序是 netcoreapp3.1
。它运行良好,除了一个我无法解释的问题。
csproj 文件一直是这样配置的(只有一个片段):
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsversion>v3</AzureFunctionsversion>
<UserSecretsId>...</UserSecretsId>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
</PropertyGroup>
<ItemGroup>
<packagereference Include="Google.Cloud.Asset.V1" Version="2.6.0" />
</ItemGroup>
还有许多其他软件包,但这是有问题的那个。在 Windows 上一切正常,一切都很好。在 Linux(或 WSL2)上,该应用程序也可以正常构建,Functions Host 启动并且一切正常,直到我们找到使用 Google.Cloud.Asset.V1
包的代码。这个包引用了 Grpc.Core
,然后代码失败了
System.Private.CoreLib: Exception while executing function: inventory. Grpc.Core: Error loading native library. Not found in any of the possible locations: /mnt/c/development/app/App.Functions/bin/Debug/netcoreapp3.1/bin/libgrpc_csharp_ext.x64.so,/mnt/c/development/app/App.Functions/bin/Debug/netcoreapp3.1/bin/runtimes/linux/native/libgrpc_csharp_ext.x64.so,/mnt/c/development/app/App.Functions/bin/Debug/netcoreapp3.1/bin/../../runtimes/linux/native/libgrpc_csharp_ext.x64.so.
这对我来说似乎没什么意义,因为这曾经有效,但最近 csproj
中的任何内容都没有改变,除了添加的其他依赖项,但与此无关。
签入 bin/Debug/netcoreapp3.1/bin/runtimes
没有 linux
只有 Windows。
但是我确实在这里看到了这个目录,但它似乎不在错误消息中的搜索路径中。这是bin/Debug/netcoreapp3.1/runtimes
。
有人知道我怎样才能让它再次工作吗?
我尝试将 <RuntimeIdentifier>
或 <RuntimeIdentifiers>
添加到 csproj 中,但这并没有改变任何东西。
解决方法
这似乎是 Grpc.Core 2.34.0 中修复的问题(我相信是 this commit)。如果你添加一个对 Grpc.Core 2.34.0 的显式依赖,像这样:
<PackageReference Include="Grpc.Core" Version="2.34.0" />
...这似乎解决了它。我仍然不知道为什么将运行时复制到 Windows 的“旧”预期位置,而不是 Linux - 感觉就像是 Azure Functions SDK 问题。但是对于 Grpc.Core 2.34.0,本机扩展加载器“知道”在父 bin/runtimes
目录中的何处找到它。