All rules
CA1877Performance Enabled by default: As suggestion

Use Path.Combine or Path.Join overloads

Use Path.Combine or Path.Join overloads

Microsoft docs

Description

When you use multiple consecutive Path.Combine or Path.Join operations, it's more efficient to use an overload that accepts multiple path segments. This approach reduces the number of allocations and function calls, improving performance. Both methods provide overloads that accept multiple parameters, allowing you to collapse consecutive operations into a single call.

Cause

Multiple consecutive System.IO.Path.Combine or System.IO.Path.Join operations are used to build a path.

How to fix violations

Replace consecutive Path.Combine or Path.Join operations with a single call using an overload that accepts all path segments.

A *code fix* that automatically performs this transformation is available.

Example

#pragma warning disable CA1877
// The code that's violating the rule is on this line.
#pragma warning restore CA1877

When to suppress

It's safe to suppress a warning from this rule if performance isn't a concern.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0