XElement and XDocument in LINQ raise exception when an attribute value contains a special character

EDN Admin

Staff member
Joined
Aug 7, 2010
Location
In the Machine
Hi,
The below code is throwing xmlException -var appContexts = from suitFile in GetValidSuitFiles(directoryToTraverse)
let contextNode = XElement.Load(suitFile)
where IsAppContextNode(contextNode) &&
contextNode.HasElements &&
IsAppContextCodeGenerated(contextNode)
select new AppContextInfo(contextNode);

Exception is coming from XElement.Load(fileName). The file contains a special character as part of the value of an attribute not in the attribute name or the tag name.
The exception obtained is -
"<special character is here. I copied it but could not paste it.>, hexadecimal value 0x03, is an invalid character. Line 287, position 103.".
We need to be able to load the file with the special character and we also need to use LINQ as we need to process 100s of files.
Any help is appreciated.
Regards,
Rajesh

View the full article
 
Top