While adding nullable annotations to System.DirectoryServices I've found few inconsistencies which need a bit more investigation or some more background in the area.
- Consider making
PropertyManager.GetPropertyValue return non-nullable. Currently it's marked as returning nullable because there is currently nothing guarding against publicly available DirectoryEntry.Properties[anyName].Add(null) which means it technically can return null. I'm not sure we can ever get null from the network.
- DirectorySearcher.Filter is currently marked as nullable but there are couple of clues it actually should be marked as:
[AllowNull] public string Filter ... - the reason it's marked as nullable is because:
public DirectorySearcher(DirectoryEntry? searchRoot, string? filter, string[]? propertiesToLoad, SearchScope scope) is assigning filter directly and does not do any validation
- Most likely constructor should be assigning to the property rather than field - in my opinion it's not intentional but I'm not 100% sure on that and we try to avoid making any product changes during nullable annotations
- in Utils.cs:
internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string? filter, ArrayList propertiesWithRangeRetrieval, ArrayList propertiesWithoutRangeRetrieval, SearchScope searchScope) is being called with explicit null from DirectoryServer.cs GetParitions() (call goes through internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string? filter, ArrayList propertiesToLoad, SearchScope searchScope))
While adding nullable annotations to System.DirectoryServices I've found few inconsistencies which need a bit more investigation or some more background in the area.
PropertyManager.GetPropertyValuereturn non-nullable. Currently it's marked as returning nullable because there is currently nothing guarding against publicly availableDirectoryEntry.Properties[anyName].Add(null)which means it technically can returnnull. I'm not sure we can ever getnullfrom the network.[AllowNull] public string Filter ...- the reason it's marked as nullable is because:public DirectorySearcher(DirectoryEntry? searchRoot, string? filter, string[]? propertiesToLoad, SearchScope scope)is assigning filter directly and does not do any validationinternal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string? filter, ArrayList propertiesWithRangeRetrieval, ArrayList propertiesWithoutRangeRetrieval, SearchScope searchScope)is being called with explicit null from DirectoryServer.csGetParitions()(call goes throughinternal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string? filter, ArrayList propertiesToLoad, SearchScope searchScope))