Possible null reference argument for parameter 'value' in 'bool string.Contains(string value)'
the warning is on this line on the existing
var link = Links.FirstOrDefault(linkItem => linkItem?.Contains(existing) ?? false);
the code
public void PrepareLinks()
{
LinksAndFileNames.Clear();
Links.Clear();
GenerateRadarLinks();
// Exclude links for files that already exist in the folder
foreach (var existing in Directory.GetFiles(Folder, "*.png").Select(Path.GetFileNameWithoutExtension))
{
var link = Links.FirstOrDefault(linkItem => linkItem?.Contains(existing) ?? false);
if (link != null)
{
Links.Remove(link);
}
}
}
Path.GetFileNameWithoutExtensionreturns astring?. Such a value could contain anull(even though realistically it's not going to).You could just say "ignore it" with the
!postfix operatorOr test it
You can however improve the efficiency of your method with two things
EnumerateFilesinstead ofGetFiles, as the latter returns an array.If you want to remove all possible matches, you can simply do