In Dynamics CRM online, I have a record in the annotation entity which has an XML attached. From a plugin, I need to get the content of that attachment and create an XML element so I can deserialize its content as an object class and apply some logic.
As we are in an online implementation, I cannot do things like create a file and read its content. So what we have is a document content in the attached file, which is a string with multiple characters, as you can see here (attachment is generated by a Power Automate flow):
Here is some of my code:
byte[] fileContentBytes = Encoding.Default.GetBytes(note.DocumentBody);
MemoryStream stream = new MemoryStream(fileContentBytes);
StreamReader globalReader = new StreamReader(stream);
XmlDocument doc = new XmlDocument();
doc.Load(globalReader);
The error message says that Data at the root level is invalid. Line 1, position 1
, as it's trying to parse as an XML something that is not parse-able as that.