当尝试加载 xml 文档进行解析时,我不断收到以下错误:
An exception of type 'System.UnauthorizedAccessException' occurred in System.Private.Xml.dll but was not handled in user code
Access to the path 'C:\Users\Delan\Code\Questions.xml' is denied.
这是一个文件,而不是目录。该文件不是只读的。它具有完整的系统访问权限。我正在管理员模式下运行 VS Code。我已将该文件移动到其他几个目录中,甚至创建了新目录。我看不出我的代码有什么问题会出现此错误。经过几个小时的搜索,似乎上述解决方案对其他人有效,但对我不起作用。 任何帮助或推动正确的方向将不胜感激。
我当前保存的代码:
XmlDocument doc = new XmlDocument();
string path = @"C:\\Users\\Delan\\Code\\Questions.xml";
doc.Load(path); // This is what causes the error
我猜你的管理员,但你确定你的应用程序以管理员身份运行还是使用其他组/用户?