Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unhandled error occurs when loading a file with invalid XML forma… #438

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions src/Application/FormSchemas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,22 +796,36 @@ public XmlSchema ValidateSchema(DataGridViewRow row, string filename)
public XmlSchema LoadSchema(string filename)
{
if (string.IsNullOrEmpty(filename)) return null;
using (var r = new XmlTextReader(filename, new NameTable()))
try
{
return XmlSchema.Read(r, (sender, args) =>
using (var r = new XmlTextReader(filename, new NameTable()))
{
if (args.Exception is XmlSchemaException se)
return XmlSchema.Read(r, (sender, args) =>
{
LogError($"{args.Message} See line {se.LineNumber} pos {se.LinePosition} of {se.SourceUri}");
}
else
{
LogError(args.Message);
}
});
if (args.Exception is XmlSchemaException se)
{
this.LogError($"{args.Message} See line {se.LineNumber} pos {se.LinePosition} of {se.SourceUri}");
}
else
{
this.LogError(args.Message);
}
});
}
}
catch (XmlException xe)
{
// The files that do not meet the basic XML structure,
// such as empty files or files with unclosed tags
this.LogError($"{xe.Message} See line {xe.LineNumber} pos {xe.LinePosition} of {xe.SourceUri}");
return null;
}
catch (Exception e)
{
this.LogError(e.Message);
return null;
}
}

}

class SchemaDialogNewRow : SchemaDialogCommand
Expand Down