是什么原因造成NotSupportedException异常("不支持&QUOT给定的路径的格式),同时使用有效的路径?路径、不支持、异常、有效

2023-09-03 00:10:17 作者:预见,离别

我写一个简单的控制台应用程序,它会从测试文件读取XML并将其反序列化到一个对象。

I am writing a simple console application that will read xml from a test file and deserialize it to an object.

var s = File.ReadAllBytes("‪G:\\Temp\\Publishing\\2.txt");
Stream _response = File.OpenRead("‪G:\\Temp\\Publishing\\2.txt");
var s = File.ReadAllBytes(@"‪g:\temp\publishing\2.txt");
var s = File.ReadAllBytes(@"‪G:\Temp\Publishing\2.txt");

我已经尝试了所有上述的读取文件,它总是会抛出 NotSupportedException异常与消息

不支持给定路径的格式。

The given path's format is not supported.

什么是上面的路径格式错误?

What is the format-error in the above path?

推荐答案

据引用来源:http://referencesource.microsoft.com/#mscorlib/system/io/filestream.cs#749

NotSupportedException异常将被抛出,如果指数的在你的路径是在第三位置或更高版本。 (人们会期望是第二个字符),你肯定没有零宽度组合字符或其他类似的Uni code有心计在源回事?

NotSupportedException will be thrown if the index of the : in your path is at the third position or later. (One would expect : to be the second character) Are you sure there are no zero-width combining characters or other similar Unicode shenanigans going on in your source?