尝试在 WinRT 中创建名称包含冒号的文件夹时出现 HRESULT E_FAIL [英] HRESULT E_FAIL when trying to create a folder that's name contains a colon in WinRT

查看:31
本文介绍了尝试在 WinRT 中创建名称包含冒号的文件夹时出现 HRESULT E_FAIL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有一个 StorageFolder 对象并尝试创建一个名称在内部某处(不是开头或结尾)包含冒号的文件夹,会导致 COM 错误,HRESULT 80004005 (HRESULT E_FAIL).

Having a StorageFolder object and trying to create a folder with a name that contains a colon somewhere inside (not at the beginning or the end) results in a COM error with HRESULT 80004005 (HRESULT E_FAIL).

示例:等待 ApplicationData.Current.TemporaryFolder.CreateFolderAsync("abc:xyz",CreationCollisionOption.OpenIfExists);

Example: await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("abc:xyz", CreationCollisionOption.OpenIfExists);

如果冒号在开头或结尾,我会收到 HRESULT 8007007b,并显示消息文件名、目录名或卷标语法不正确".没关系.

If the colon is at the beginning ot at the end I get a HRESULT 8007007b with the message "The filename, directory name, or volume label syntax is incorrect". That's fine.

我检查了其他无效字符,但只有冒号导致 E_FAIL.

I checked with other invalid chars but only a colon leads to E_FAIL.

如果用户输入文件夹名称,这可能会出现问题.解决方法当然是简单地检查文件名中的冒号.

This may be a problem if the user enters the folder name. Workaround is of course to simply check for a colon in the filename.

有人知道 E_FAIL 错误的可能原因吗?我假设 COM 认为文件夹名称以 URI 开头,但当然无法弄清楚它是什么类型的 URI.

Does anyone know a possible reason for the E_FAIL error? I assume that COM thinks the foldername starts with an URI but can of course not figure out what kind of URI it is.

推荐答案

好吧,COM 臭名昭著的错误报告又回来了.多年来,我们已经被 .NET 出色且信息丰富的异常所宠坏,但该地毯被 WinRT 拉走了.COM 是底层互操作机制,HRESULT 是报告错误的方式.

Well, COM's infamous error reporting is back with a vengeance. We've gotten spoiled from years of .NET's excellent and informative exceptions but that rug got pulled by WinRT. COM is the underlying interop mechanism and HRESULTs are the way errors get reported.

E_FAIL 是规范错误代码,您可以获得的唯一描述性文本是未指定的错误".这是准确的,处理该代码的 Microsoft 程序员不能或不想产生更具描述性的错误.另一个很棒的东西是 E_UNEXPECTED,它转化为灾难性故障".术语灾难性"实际上是指错误消息的价值(如果您得到它).

E_FAIL is the canonical error code, the only descriptive text you can get with that is "Unspecified error". Which is accurate, the Microsoft programmer that handled that code could not or did not want to produce a more descriptive error. Another great doozy is E_UNEXPECTED, it translates to "Catastrophic failure". The term "catastrophic" really refers to the value of the error message if you ever get it.

推测一下,abc:xyz"路径字符串实际上是有效的.它指的是一个名为xyz"的备用数据流,存储在文件abc"中.因此,首先检查路径字符串不会引起臭味.但是,您正在按该名称创建文件夹,而不是文件.文件夹不能有备用数据流.显然这是很晚才发现的,为时已晚,仍然无法产生更准确的错误代码.它应该产生了一个 Windows 错误,并且通过将其与 0x8007000 进行或运算将它们适当地包装在 HRESULT 中,但由于不可猜测的原因而没有这样做.

Speculating somewhat, the "abc:xyz" path string is actually valid. It refers to an alternate data stream named "xyz", stored in file "abc". So checking the path string isn't going to raise a stink, at first. You are however creating a folder by that name, not a file. A folder cannot have an alternate data stream. Apparently this is discovered very late, too late to still produce a more accurate error code. It should have produced a Windows error and they are wrapped appropriately in a HRESULT by or-ing it with 0x8007000 but that wasn't done for unguessable reasons.

无法发送有关此的反馈,Windows 组没有 DevDiv 的 connect.microsoft.com 等效项.好在你知道是什么导致了错误.

No way to send feedback about this, the Windows group doesn't have the equivalent of DevDiv's connect.microsoft.com. Good thing you know what caused the error.

这篇关于尝试在 WinRT 中创建名称包含冒号的文件夹时出现 HRESULT E_FAIL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆