Skip to content

Commit b07d928

Browse files
committed
human edits
1 parent 73ddd9d commit b07d928

File tree

5 files changed

+36
-48
lines changed

5 files changed

+36
-48
lines changed

docs/fundamentals/code-analysis/quality-rules/ca2017.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
---
22
title: "CA2017: Parameter count mismatch (code analysis)"
33
description: "Learn about code analysis rule CA2017: Parameter count mismatch"
4-
ms.date: 01/19/2022
5-
ai-usage: ai-generated
4+
ms.date: 09/24/2025
5+
ai-usage: ai-assisted
66
f1_keywords:
77
- "LoggerMessageDefineAnalyzer"
88
- "CA2017"
99
helpviewer_keywords:
1010
- "LoggerMessageDefineAnalyzer"
1111
- "CA2017"
1212
author: Youssef1313
13+
dev_langs:
14+
- CSharp
15+
- VB
1316
---
1417
# CA2017: Parameter count mismatch
1518

docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/all-rules.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<RootNamespace>all_rules</RootNamespace>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
12-
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
13-
<PackageReference Include="System.Security.Permissions" Version="8.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
12+
<PackageReference Include="System.Data.OleDb" Version="10.0.0-rc.1.25451.107" />
13+
<PackageReference Include="System.Security.Permissions" Version="9.0.0" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2017.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ca2017
44
{
5-
//<snippet1>
5+
// <snippet1>
66
public class LoggingExample
77
{
88
private readonly ILogger<LoggingExample> _logger;
@@ -17,21 +17,15 @@ public void ExampleMethod()
1717
string name = "Alice";
1818
int age = 30;
1919

20-
// Violates CA2017: Too few arguments for placeholders
20+
// Violates CA2017: Too few arguments for placeholders.
2121
_logger.LogInformation("User {Name} is {Age} years old and lives in {City}", name, age);
2222

23-
// Violates CA2017: Too many arguments for placeholders
23+
// Violates CA2017: Too many arguments for placeholders.
2424
_logger.LogError("Error occurred: {Message}", "Something went wrong", "Extra argument");
2525

26-
// Correct usage: Matching number of placeholders and arguments
26+
// Correct usage: Matching number of placeholders and arguments.
2727
_logger.LogInformation("User {Name} is {Age} years old", name, age);
28-
29-
// Correct usage: No placeholders, no arguments
30-
_logger.LogInformation("Application started");
31-
32-
// Correct usage: Single placeholder, single argument
33-
_logger.LogWarning("Failed to process {FileName}", "document.txt");
3428
}
3529
}
36-
//</snippet1>
37-
}
30+
// </snippet1>
31+
}

docs/fundamentals/code-analysis/quality-rules/snippets/vb/all-rules/all-rules.vbproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<RootNamespace>all_rules</RootNamespace>
6-
<TargetFramework>net8.0</TargetFramework>
6+
<TargetFramework>net9.0</TargetFramework>
77
<NoWarn>$(NoWarn);SYSLIB0050</NoWarn>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
12+
<PackageReference Include="System.Data.OleDb" Version="10.0.0-rc.1.25451.107" />
1213
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
13-
<PackageReference Include="System.Security.Permissions" Version="8.0.0" />
14+
<PackageReference Include="System.Security.Permissions" Version="9.0.0" />
1415
</ItemGroup>
1516

1617
</Project>
Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
1-
Imports Microsoft.Extensions.Logging
1+
Imports Microsoft.Extensions.Logging
22

3-
Namespace ca2017
3+
Public Class LoggingExample
44

5-
Public Class LoggingExample
5+
Private ReadOnly _logger As ILogger(Of LoggingExample)
66

7-
Private ReadOnly _logger As ILogger(Of LoggingExample)
7+
Public Sub New(logger As ILogger(Of LoggingExample))
8+
_logger = logger
9+
End Sub
810

9-
Public Sub New(logger As ILogger(Of LoggingExample))
10-
_logger = logger
11-
End Sub
11+
Public Sub ExampleMethod()
12+
Dim name As String = "Alice"
13+
Dim age As Integer = 30
1214

13-
Public Sub ExampleMethod()
14-
Dim name As String = "Alice"
15-
Dim age As Integer = 30
15+
' Violates CA2017: Too few arguments for placeholders.
16+
_logger.LogInformation("User {Name} is {Age} years old and lives in {City}", name, age)
1617

17-
' Violates CA2017: Too few arguments for placeholders
18-
_logger.LogInformation("User {Name} is {Age} years old and lives in {City}", name, age)
18+
' Violates CA2017: Too many arguments for placeholders.
19+
_logger.LogError("Error occurred: {Message}", "Something went wrong", "Extra argument")
1920

20-
' Violates CA2017: Too many arguments for placeholders
21-
_logger.LogError("Error occurred: {Message}", "Something went wrong", "Extra argument")
21+
' Correct usage: Matching number of placeholders and arguments.
22+
_logger.LogInformation("User {Name} is {Age} years old", name, age)
23+
End Sub
2224

23-
' Correct usage: Matching number of placeholders and arguments
24-
_logger.LogInformation("User {Name} is {Age} years old", name, age)
25-
26-
' Correct usage: No placeholders, no arguments
27-
_logger.LogInformation("Application started")
28-
29-
' Correct usage: Single placeholder, single argument
30-
_logger.LogWarning("Failed to process {FileName}", "document.txt")
31-
End Sub
32-
33-
End Class
34-
35-
End Namespace
25+
End Class

0 commit comments

Comments
 (0)