在 linux 上运行 .NET Core 应用程序时出错

问题描述 投票:0回答:0

我在 linux 环境 (CentOS 7) 上运行 .NET 6 应用程序。我使用以下命令发布了应用程序:

dotnet publish app -c release -r centos.7-x64 --self-contained true
.

因为它是一个独立的应用程序,所以我没有在 centOS 环境上安装任何 sdks。将文件复制到 CentOS 环境后,我使用

./appName
.

运行应用程序

这是我收到的错误:

   System.ArgumentException: The path is empty. (Parameter 'path')
   at System.IO.Path.GetFullPath(String path)
   at System.IO.DirectoryInfo..ctor(String path)
   at <>c.<CreateHostBuilder>b__1_0(HostBuilderContext hostContext, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Program.Main(String[] args)

我认为这是我收到此错误的地方(无法找到路径):

services.AddDataProtection()
                .PersistKeysToFileSystem(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)));

我尝试在线查看,但我无法弄清楚为什么会发生这种情况或可能的解决方案是什么。

P.S:为 OSx64 发布相同的应用程序有效并且没有给我同样的错误。

linux .net-6.0
© www.soinside.com 2019 - 2024. All rights reserved.