Title: CA2208 should not report a violation when `paramName` not specified in a property · Issue #5209 · dotnet/roslyn-analyzers · GitHub
Open Graph Title: CA2208 should not report a violation when `paramName` not specified in a property · Issue #5209 · dotnet/roslyn-analyzers
X Title: CA2208 should not report a violation when `paramName` not specified in a property · Issue #5209 · dotnet/roslyn-analyzers
Description: Analyzer Diagnostic ID: CA2208: Instantiate argument exceptions correctly Describe the improvement Specifying value as a paramName for ArgumentException in a property does not add any value over what the stack trace provides, therefore a...
Open Graph Description: Analyzer Diagnostic ID: CA2208: Instantiate argument exceptions correctly Describe the improvement Specifying value as a paramName for ArgumentException in a property does not add any value over wh...
X Description: Analyzer Diagnostic ID: CA2208: Instantiate argument exceptions correctly Describe the improvement Specifying value as a paramName for ArgumentException in a property does not add any value over wh...
Opengraph URL: https://github.com/dotnet/roslyn-analyzers/issues/5209
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"CA2208 should not report a violation when `paramName` not specified in a property","articleBody":"### Analyzer\r\n\r\n**Diagnostic ID**: [CA2208: Instantiate argument exceptions correctly](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)\r\n\r\n### Describe the improvement\r\n\r\nSpecifying `value` as a `paramName` for `ArgumentException` in a property does not add any value over what the stack trace provides, therefore a violation should not be reported.\r\n\r\n### Example\r\n\r\n#### Existing violation\r\n\r\n```csharp\r\ninternal string Property\r\n{\r\n set\r\n {\r\n _backing = value ?? throw new ArgumentNullException(); // CA2208 violation\r\n }\r\n}\r\n```\r\n\r\nCreates the message:\r\n```\r\nValue cannot be null.\r\n```\r\n\r\n#### Fix of violation\r\n\r\n```csharp\r\ninternal string Property\r\n{\r\n set\r\n {\r\n _backing = value ?? throw new ArgumentNullException(nameof(value));\r\n }\r\n}\r\n```\r\n\r\nCreates the message:\r\n```\r\nValue cannot be null.\r\nParameter name: value\r\n```\r\n\r\n### Additional context\r\n\r\nThe book, [Framework Design Guidelines (2008)](https://docs.microsoft.com/dotnet/standard/design-guidelines/using-standard-exception-types#argumentexception-argumentnullexception-and-argumentoutofrangeexception) from Addison-Wesley Microsoft Technology Series does recommend using the implicit value parameter of property setters for `paramName` but it is not explained why this is worthwhile.\r\n\r\n\r\n### See also\r\n\r\nhttps://github.com/dotnet/roslyn-analyzers/issues/1561","author":{"url":"https://github.com/xtqqczze","@type":"Person","name":"xtqqczze"},"datePublished":"2021-07-05T20:09:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/5209/roslyn-analyzers/issues/5209"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3fdfa3e4-141c-0b24-791a-19eb02e52dd6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F98:262BEC:12CBE4D:188F76D:6992B6AF |
| html-safe-nonce | 9206e3ed0be6a160a06092334241e795b69692dd4659edde1748f7f9e85ab9ee |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Rjk4OjI2MkJFQzoxMkNCRTREOjE4OEY3NkQ6Njk5MkI2QUYiLCJ2aXNpdG9yX2lkIjoiMjIxMjQ1NjkzMTQ3NzU5OTkxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 85b0628509d050e7f8d08d5a8867ec4ebb9743836b33e8f65c15943c2aa70156 |
| hovercard-subject-tag | issue:937340232 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/dotnet/roslyn-analyzers/5209/issue_layout |
| twitter:image | https://opengraph.githubassets.com/66198d8bc6fa27c2531b7e3bbe6425a6407e36ab609ea3c3e8dfc8da66e6860f/dotnet/roslyn-analyzers/issues/5209 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/66198d8bc6fa27c2531b7e3bbe6425a6407e36ab609ea3c3e8dfc8da66e6860f/dotnet/roslyn-analyzers/issues/5209 |
| og:image:alt | Analyzer Diagnostic ID: CA2208: Instantiate argument exceptions correctly Describe the improvement Specifying value as a paramName for ArgumentException in a property does not add any value over wh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | xtqqczze |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/dotnet/roslyn-analyzers git https://github.com/dotnet/roslyn-analyzers.git |
| octolytics-dimension-user_id | 9141961 |
| octolytics-dimension-user_login | dotnet |
| octolytics-dimension-repository_id | 36946704 |
| octolytics-dimension-repository_nwo | dotnet/roslyn-analyzers |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36946704 |
| octolytics-dimension-repository_network_root_nwo | dotnet/roslyn-analyzers |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 66ca5c603f1805ef71d7e467df063440818799b5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width