与 Microsoft 创建了错误报告:
https ://connect.microsoft.com/VisualStudio/Feedback/Details/2046491
目前,我正在通过(通过反射进行黑客攻击)从 Uri 类中的 UriParser 对象中删除两个标志来解决这个问题:
当我的应用程序实例化时,我调用了下面的方法一次。实例化后,每个 FTP Uri 对象在解析时都会使用新的标志组合。
// CompressPath = 0x800000, // For an authority based Uri remove/compress /./ /../ in the path
// UnEscapeDotsAndSlashes = 0x2000000, // additionally unescape dots and slashes before doing path compression
/// <summary>
/// http://referencesource.microsoft.com/#System/net/System/_UriSyntax.cs
/// </summary>
public static void LeaveDotsAndSlashesEscaped() {
Uri uri = new Uri("ftp://myUrl/%2E%2E/%2E%2E/");
if (uri == null) {
throw new ArgumentNullException("uri");
}
FieldInfo fieldInfo = uri.GetType().GetField("m_Syntax", BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo == null) {
throw new MissingFieldException("'m_Syntax' field not found");
}
object uriParser = fieldInfo.GetValue(uri);
fieldInfo = typeof(UriParser).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo == null) {
throw new MissingFieldException("'m_Flags' field not found");
}
object uriSyntaxFlags = fieldInfo.GetValue(uriParser);
// Clear the flags that we don't want
uriSyntaxFlags = (int)uriSyntaxFlags & ~0x2000000 & ~0x800000;
fieldInfo.SetValue(uriParser, uriSyntaxFlags);
}