Skip to content

Commit 96d5ee0

Browse files
committed
Avoid a first-chance FileNotFoundException when a ruleset include is not found.
When a .ruleset file includes a non-existing ruleset reference we receive null from ResolveIncludePath and throw a FileNotFoundException, which is the immediately caught in LoadRuleSet. We can avoid the first-chance exception and the associated allocations if we just return null. A missing ruleset is not an exceptional situation so no need to use exceptions for control flow here if we can avoid it.
1 parent 6f09af8 commit 96d5ee0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Compilers/Core/Portable/RuleSet/RuleSetInclude.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public RuleSet LoadRuleSet(RuleSet parent)
5555
try
5656
{
5757
path = GetIncludePath(parent);
58+
if (path == null)
59+
{
60+
return null;
61+
}
62+
5863
ruleSet = RuleSetProcessor.LoadFromFile(path);
5964
}
6065
catch (FileNotFoundException)
@@ -78,11 +83,9 @@ public RuleSet LoadRuleSet(RuleSet parent)
7883
private string GetIncludePath(RuleSet parent)
7984
{
8085
var resolvedIncludePath = ResolveIncludePath(_includePath, parent?.FilePath);
81-
82-
// If we still couldn't find it then throw an exception;
8386
if (resolvedIncludePath == null)
8487
{
85-
throw new FileNotFoundException(string.Format(CodeAnalysisResources.FailedToResolveRuleSetName, _includePath), _includePath);
88+
return null;
8689
}
8790

8891
// Return the canonical full path

0 commit comments

Comments
 (0)