Ce serait fantastique si vous pouviez m'aider à me débarrasser de ces avertissements ci-dessous. Je n'ai pas réussi à trouver un bon document. Puisque les avertissements sont concentrés dans la section private void ValidateConfiguration(XmlNode section)
, j'espère que ce n'est pas si difficile à répondre si vous l'avez déjà rencontré.Aidez-moi à convertir le code de validation .NET 1.1 Xml en .NET 2.0 s'il vous plaît
Merci!
'System.Configuration.ConfigurationException.ConfigurationException(string)' is obsolete: 'This class is obsolete, to create a new exception create a System.Configuration!System.Configuration.ConfigurationErrorsException'
'System.Xml.XmlValidatingReader' is obsolete: 'Use XmlReader created by XmlReader.Create() method using appropriate XmlReaderSettings instead. http://go.microsoft.com/fwlink/?linkid=14202'
private void ValidateConfiguration(XmlNode section)
{
// throw if there is no configuration node.
if(null == section)
{
throw new ConfigurationException("The configuration section passed within the ... class was null ... there must be a configuration file defined.", section);
}
//Validate the document using a schema
XmlValidatingReader vreader = new XmlValidatingReader(new XmlTextReader(new StringReader(section.OuterXml)));
// open stream on Resources; the XSD is set as an "embedded resource" so Resource can open a stream on it
using (Stream xsdFile = XYZ.GetStream("ABC.xsd"))
using (StreamReader sr = new StreamReader(xsdFile))
{
vreader.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
vreader.Schemas.Add(XmlSchema.Read(new XmlTextReader(sr), null));
vreader.ValidationType = ValidationType.Schema;
// Validate the document
while (vreader.Read()) { }
if (!_isValidDocument)
{
_schemaErrors = _sb.ToString();
throw new ConfigurationException("XML Document not valid");
}
}
}
// Does not cause warnings.
private void ValidationCallBack(object sender, ValidationEventArgs args)
{
// check what KIND of problem the schema validation reader has;
// on FX 1.0, it gives a warning for "<xs:any...skip" sections. Don't worry about those, only set validation false
// for real errors
if(args.Severity == XmlSeverityType.Error)
{
_isValidDocument = false;
_sb.Append(args.Message + Environment.NewLine);
}
}
Avez-vous essayé de faire les changements suggérés dans les mises en garde? Si oui, avez-vous eu des problèmes? –
Je pense qu'il cherche comment faire ces changements. Le lien fourni dans l'avertissement n'est pas utile. –
Vous n'avez pas besoin de convertir de C# 1.1 à C# 2.0 (d'autant plus qu'il n'y a pas de C# 1.1). Vous devez convertir .NET 1.1 en .NET 2.0. –