我正在尝试使用system.net节在.Net 6中的app.config中,但是失败了:
System.Configuration.ConfigurationErrorsException:‘配置系统未能初始化’内部异常: ConfigurationErrorsException:无法识别的配置节system.net
知道问题出在哪里吗?
该方案:
using System.Configuration;
string? bogus = ConfigurationManager.AppSettings["Bogus"];
Console.WriteLine($"Hello, {bogus}!");app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<settings>
<servicePointManager expect100Continue="false" useNagleAlgorithm="false" />
</settings>
</system.net>
<appSettings>
<add key="Bogus" value="Bogus" />
</appSettings>
</configuration>首席执行官:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
</ItemGroup>
</Project>发布于 2022-06-28 16:26:18
显然它不再支持了
这是设计上的,您不能在配置下有没有定义的部分。system.net通常在machine.config中定义,但.NET Core没有定义,因为.NET中不存在类型(System.Net.Configuration.NetSectionGroup)。
https://stackoverflow.com/questions/72789661
复制相似问题