Unfortunately, entities are part of XML validation rules ( 2.1 Well-formed XML documents ). It sounds like you are saying that you want XDocument.Load load what is an XML file, but really does not comply with the rules that it will not do, reasonably enough.
If your users give you what should be XML files, but have undefined entities, then either you must force them to provide files in a valid format, or manage the error yourself at boot time, as suggested.
It seems to me, based on your limitations, that the most accurate approach would be to follow a related example and create some settings to go into the XMLReader by line ( Validating an XML document in the DOM ).
If there are entities that are not defined and not specified in public schemas, you need to create your own schema that defines all the entities you need. So, create generic settings for the XMLReader that references your own custom schema. Add the necessary objects to this schema, as certain files are not loaded, and then you create a list of all the topics that you need to determine for the XML files to be valid.
Then, for each loaded document, create an XMLReader for the file using the settings above and invoke the XDocument (XMLReader) overload.
source share