XML read fails on unknown xmlns field
See original GitHub issueI am trying to read a standard Visual Studio NET Framework project file using ChoXmlReader (v1.1.28) as shown below. I’m running .28 because I have many project files that use ChoXmlReader and I don’t want to update them all unless I have to. The first two lines of the project file are:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
My code that reads the file looks like this:
// parse the file and return the result
try {
var tmp = new ChoXmlReader<Project>(path).WithXPath("//").ToList();
The problem is that the read “fails” (does not load the project file elements) because of the broken xmlns https pathname. Putting the pathname into my browser shows the following error message:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
If I remove the xmlns attribute from the file, the ChoXmlReader code above properly reads the XML file. Is there any way that the ChoXmlReader could ignore broken xmlns pathnames? I don’t think VStudio is going to stop generating the xmlns for NET Framework project files any time soon.
I do not get an exception raised by ChoXmlReader, either. It properly reads and returns the “ToolsVersion” attribute on the Project line of the example above. So ChoXmlReader says there is no error (no exception) with the file, but it returns a class that is essentially empty and unusable. If it was my code, I would try to fail gracefully and ignore broken xmlns paths. I guess the file itself has a valid syntax, but the URL is broken. I vote for failing gracefully and ignoring the broken URL so that the reader could try to read the rest of the file. Thank you for the wonderful library!
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Thank you so much for your help! It would have been impossible for me to figure that out on my own without doc. I think VStudio requires that xmlns line, so it might not be possible to remove it from all my project files. And it would probably get added back in on the rewrite of the csproj file the next time I changed a project property. Thank you!
rolled out new beta version ChoETL.Core v1.2.1.43-beta2, handle the default namespace implicitly.
Sample fiddle: https://dotnetfiddle.net/JLICyi