Blazor中的XML ... Wasm:[System.PlatformNotSupportedException]此平台不支持操作

问题描述 投票:1回答:1

我正在尝试在Blazor中做一些XML的东西,我只能得到2条错误消息。我尝试的第一件事(使用本地XML文件)甚至找不到它......

string xmlPath = "C:\\Users\\me\\Desktop\\users.xml";
XElement contacts = XElement.Load(xmlPath);
Console.WriteLine(contacts);

这给出了WASM的错误:

[System.IO.FileNotFoundException]找不到文件“/C:\Users\me\Desktop\users.xml”

它在路径的开头添加了一个/。

或者,如果我使用随机在线XML,我会收到“不支持”错误。例如...

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("https://www.w3schools.com/xml/note.xml");

Wasm中显示的完整错误:

[System.PlatformNotSupportedException]此平台不支持此操作。

是不是Web Assembly不支持XML类或类似的东西?

xml webassembly blazor
1个回答
1
投票

Web Assembly和JavaScript无法访问驻留在用户浏览器上的本地文件。当您尝试访问本地文件时,Web Assembly会显示一条通知消息,告知用户无法找到该文件。这是这种情况下的标准程序。

至于第二个错误:你要做的是从Blazor应用程序向驻留在不同域上的服务器发出http请求,这需要你配置CORS,但这不是主要问题。 XmlDocument无法使用HttpClient调用http请求。我不确定它是否可以创建它自己的HttpClient实例,如果确实如此,这个HttpClient应该配置相同的设置,Blazor定义的默认HttpCient设置为...

希望这可以帮助...

© www.soinside.com 2019 - 2024. All rights reserved.