diff --git a/PInvoke/Shell32/KnownFolderIdExt.cs b/PInvoke/Shell32/KnownFolderIdExt.cs
index 41b8a543..645bb0c7 100644
--- a/PInvoke/Shell32/KnownFolderIdExt.cs
+++ b/PInvoke/Shell32/KnownFolderIdExt.cs
@@ -46,9 +46,8 @@ public static class KnownFolderIdExt
/// The unique identifier representing a known folder.
/// A corresponding , if found. If not, an exception is thrown.
/// guid - Provided GUID value does not correspond to a known folder.
- public static KNOWNFOLDERID KnownFolderId(this Guid guid) =>
- AssociateAttribute.TryEnumLookup(guid, out var kf) ? kf :
- throw new ArgumentOutOfRangeException(nameof(guid), "Provided GUID value does not correspond to a known folder.");
+ public static KNOWNFOLDERID? KnownFolderId(this Guid guid) =>
+ AssociateAttribute.TryEnumLookup(guid, out var kf) ? kf : null;
/// Gets a registry property associated with this known folder.
/// Return type.
@@ -66,13 +65,13 @@ public static class KnownFolderIdExt
/// Retrieves the associated with the .
/// The .
/// Matching .
- public static KNOWNFOLDERID KnownFolderId(this Environment.SpecialFolder spFolder)
+ public static KNOWNFOLDERID? KnownFolderId(this Environment.SpecialFolder spFolder)
{
if (spFolder == Environment.SpecialFolder.Personal) return KNOWNFOLDERID.FOLDERID_Documents;
if (spFolder == Environment.SpecialFolder.DesktopDirectory) return KNOWNFOLDERID.FOLDERID_Desktop;
foreach (KNOWNFOLDERID val in Enum.GetValues(typeof(KNOWNFOLDERID)).Cast())
if (val.SpecialFolder() == spFolder) return val;
- throw new InvalidCastException(@"There is not a Known Folder equivalent to this SpecialFolder.");
+ return null;
}
/// Retrieves the name associated with a .