I'm trying to do some XML stuff in Blazor and all I can get is 2 error messages. The first thing I try (using a local XML file) can't even find it...
string xmlPath = "C:\\Users\\me\\Desktop\\users.xml";
XElement contacts = XElement.Load(xmlPath);
Console.WriteLine(contacts);
This gives an error saying WASM:
[System.IO.FileNotFoundException] Could not find file "/C:\Users\me\Desktop\users.xml"
It has added a / at the start of the path.
Or if I use a random online XML, I get the 'not supported' error. For example...
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("https://www.w3schools.com/xml/note.xml");
The full error displayed in Wasm:
[System.PlatformNotSupportedException] Operation is not supported on this platform.
Is it just the case that Web Assembly doesn't support the XML classes or something like that?
Web Assembly as well as JavaScript cannot access local files residing on the user's browser. When you try to access a local file Web Assembly displays a notification message telling the user that it could not find the file. This is the standard procedure in this case.
As for the second error: What you're trying to do is making an http request from the Blazor app to a server residing on a different domain, which requires you to configure CORS, but this is not the main issue. The XmlDocument cannot invoke an http request using HttpClient. I'm not sure if it can at all create it's own HttpClient instance, and if it does, this HttpClient should be configured with the same settings the default HttpCient defined by Blazor is set...
Hope this helps...