Well, basically your application is a validator - if the configuration file is invalid, you will get an exception at startup. Other than that, I don't know any ready-made support for checking app.config files.
In your C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas you will find several files called DotNetConfig.xsd / DotNetConfig20.xsd - these are XML schema files supplied by Microsoft that you can easily use to check any other files configurations that may be available for reality.
The basic structure for programmatically checking your configurations will look something like this:
using(StreamReader xsdReader = new StreamReader(xsdFileName)) { XmlSchema Schema = new XmlSchema(); Schema = XmlSchema.Read(xsdReader, new ValidationEventHandler(XSDValidationEventHandler)); XmlReaderSettings ReaderSettings = new XmlReaderSettings(); ReaderSettings.ValidationType = ValidationType.Schema; ReaderSettings.Schemas.Add(Schema); ReaderSettings.ValidationEventHandler += new ValidationEventHandler(XMLValidationEventHandler); using(XmlTextReader xmlReader = new XmlTextReader(xmlFileName)) { XmlReader objXmlReader = XmlReader.Create(xmlReader, ReaderSettings); while (objXmlReader.Read()) { } } } Console.WriteLine("Successful validation completed!");
Now you need to make event event handlers for those events that occur when something in the scan goes wrong - about it !:-)
marc_s
source share