在this question的答案中的参考源链接之后,System.IO.FileStream.Init仅在错误定位“:”字符的情况下使用Argument_PathFormatNotSupported字符串抛出NotSupportedException一次。
但是,在我的代码中,“不支持给定路径的格式”即使出现这种情况也会引发错误,例如
PHS shape = new PHS();
try
{
string filePath = Path.GetFullPath(Path.GetDirectoryName(Application.ExecutablePath) + "\\..\\..\\Maps\\ne_50m_urban_areas.shp");
if (filePath.IndexOf(':', 2) != -1)
MessageBox.Show("filePath bad");
else
MessageBox.Show("filePath okay");
shape.LoadFile(Populated, filePath);
}
catch (NotSupportedException ee)
{
MessageBox.Show(ee.StackTrace);
}
首先运行此代码会给我“filePath okay”,但随后会给我一个带有以下堆栈的NotSupportedException:
LoadFile方法通过System.IO.File.OpenRead()调用FileStream。奇怪的是,只有当filePath具有一定长度时才抛出此错误 - 如果filePath很短,则不会抛出错误。在Win10,Win8.1和Win2003的副本上可以看到此行为。
感谢您对此行为的任何解释,谢谢。