C# 从具有非拉丁文件路径的文件加载XmlDocument

C# 从具有非拉丁文件路径的文件加载XmlDocument,c#,.net,C#,.net,我实例化了XmlDocument,然后尝试在文件pat中加载带有非拉丁符号的XML文件。在加载文件时,我面对的是 ArgumentNullException 留言: "Value cannot be null. Parameter name: str" 堆栈跟踪是- at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str) at System.Security.Permission

我实例化了XmlDocument,然后尝试在文件pat中加载带有非拉丁符号的XML文件。在加载文件时,我面对的是

 ArgumentNullException 
留言:

"Value cannot be null. Parameter name: str"
堆栈跟踪是-

at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
at System.Uri.ParseConfigFile(String file, IdnScopeFromConfig& idnStateConfig, IriParsingFromConfig& iriParsingConfig)
at System.Uri.GetConfig(UriIdnScope& idnScope, Boolean& iriParsing)
at System.Uri.InitializeUriConfig()
at System.Uri.InitializeUri(ParsingError err, UriKind uriKind, UriFormatException& e)
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlTextReaderImpl..ctor(String url, XmlNameTable nt)
at System.Xml.XmlTextReader..ctor(String url, XmlNameTable nt)
at System.Xml.XmlDocument.Load(String filename)
at .... 
我的代码中有一部分:

var xmlData = new XmlDocument();
if (File.Exists(xmlPath))
{        
    xmlData.Load(xmlPath);
    ...
}
xmlPath包含法语字母

怎么了?
如何打开非拉丁字符的xml文件?

我找到了使用其他类加载数据的解决方案,如下所示:

var d = File.ReadAllText(xmlPath);
xmlData.LoadXml(d);

但问题-“出了什么问题?”仍然打开。

首先将文件路径加载到uri中:

Uri xmlUri = new Uri(xmlPath);
xmlData.Load(xmlUri.AbsolutePath);

您是否在调试器中检查了
xmlPath
的值?我认为您的代码应该可以工作,我敢打赌
xmlPath
不包含您期望的值。xmlPath包含期望的值。我想补充一点,在加载文件之前,我正在验证文件是否存在。请告诉我们
xmlPath
的值是多少。