代码:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Builder
{
class Program
{
static void Main(string[] args)
{
FoodManager foodManager = new FoodManager();
Builder instance;
Console.WriteLine("please enter food no:");
string No = Console.ReadLine();
string foodType = ConfigurationManager.AppSettings["No"+No];
instance = (Builder)Assembly.Load("Builder").CreateInstance("Builder." + foodType);
foodManager.Construct(instance);
Food food = instance.GetFood();
food.Show();
Console.ReadLine();
}
}
}
错误信息:
System.Configuration.ConfigurationErrorsException
HResult=0x80131902
Message=配置系统未能初始化
Source=System.Configuration
StackTrace:
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.get_AppSettings()
at Builder.Program.Main(String[] args) in D:\work\WebApplication1\Builder\Program.cs:line 23
Inner Exception 1:
ConfigurationErrorsException: 无法识别的配置节 AppSettings。 (D:\work\WebApplication1\Builder\bin\Debug\Builder.exe.Config line 6)
我想问一下这个错误怎么解决呢?
看起来是配置的文件有问题,你配置文件什么写的
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<AppSettings>
<clear />
<add key="No1" value="GoldBuider"></add>
<add key="No2" value="NomalBuider"></add>
</AppSettings>
</configuration>
会长,麻烦帮忙看一下~
@StepStep: <AppSettings>
应为<appSettings>
,别忘了结贴给我园豆