我在我的一个C#批处理作业中遇到了一个奇怪的错误,所以我决定一块一块地重建它以找出造成问题的原因。事实证明,这是我以前从未见过的ConfigurationErrorsException
。这是内在的例外:
Configuration system failed to initialize System.Exception {System.Configuration.ConfigurationErrorsException}
`
当我尝试通过访问app.config
来填充变量时,会抛出此异常。下面是我到目前为止的全部代码
using System;
using BatchDashboard;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using IBM.WMQ;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
namespace LVODRM
{
class Program
{
//Job log and BatchDashboard variables
private static StreamWriter _Log;
//public static string _environment = getEnvironment();
public const string _PACKAGENAME = "LVOONX";
//BatchDashboard variables
public static int xmlRecordCount = 0;
public static int xmlProcessedCount = 0;
public static int errorCount = 0;
public static int warningCount = 0;
//MQ and Parsing variables
public static string strReturn;
public static string queueName;
public static string pathToSave;
public static string strQueueManager;
public static int backOutNumberThreshold;
static void Main(string[] args)
{
strReturn = string.Empty;
queueName = ConfigurationManager.AppSettings.Get("QueueName");
Console.Write("Hello world");
Console.ReadKey();
}
}
}
这是我的app.config文件。有人能告诉我我错过了什么吗?
<?xml version="1.0"?>
<configuration>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="LVODRM.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
<!--MQ SETTINGS-->
<add key="QueueName" value="LVO.DRM.PRODUCER.NEWAPT"/>
<add key="PathToSave" value="\\prdhilfs02\L&I-SYSTEMS\WORKAREA\AgencySystems\Public\NMF_Onyx\NMFDatafiles\NMFImportFiles\"/>
<add key="QueueManager" value="MQT_DMB01"/>
<add key="BackOutNumberThreshold" value="10"/>
</configuration>
答案 0 :(得分:3)
您缺少<appSettings>
标记。 E.g:
<appSettings>
<add key="QueueName" value="LVO.DRM.PRODUCER.NEWAPT"/>
...
</appSettings>