If exceptions were thrown while reading xml:
1. ReadXml(file, XmlReadMode.InferSchema) ---- ArgumentException may be thrown with error message:
{"The same table (Users) cannot be the child table in two nested relations." }
2. ReadXml(file, XmlReadMode.IgnoreSchema) --- No exception is thrown right now, but InvalidCastException may be thrown for some properties while getting property LATER with error message: {"Specified cast is not valid."}
so, better to read xml InferSchema defaultly, then catch the ArgumentException if encountered...
try
{
ds.ReadXml(xmlFile, XmlReadMode.InferSchema);
}
catch (ArgumentException)
{
ds.ReadXml(xmlFile, XmlReadMode.IgnoreSchema);
}
catch (Exception e)
{
ds = null;
return;
}
If System.Data.ConstraintException was thrown with following error message:
"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.", please set EnforceConstraints as false.