Generate constructor from members with "Add null checks" uses "throw new" instead of ArgumentNullException.ThrowIfNull()
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/Generate-constructor-from-members-with-/11039663)._
---
[severity:It bothers me. A fix would be nice]
If you generate a constructor as described in [this msdocs page](https://learn.microsoft.com/en-us/visualstudio/ide/reference/generate-constructor?view=visualstudio), you have an option "Add null checks".
If you check that option, a constructor similar to this one is generated:
```cs
public OrAction(InputAction[] actions)
{
Actions = actions ?? throw new ArgumentNullException(nameof(actions));
}
```
But using "throw new" is an outdated and bad pratice. Modern C# code uses throw helpers, and as [this msdocs page](https://learn.microsoft.com/en-us/dotnet/communitytoolkit/diagnostics/throwhelper) says:
> These methods are meant to be used in place of the classic throw new Exception(...) statement in code, as it will result in smaller and more efficient code.
It would be better if generated code was more similar to this:
```cs
public OrAction(InputAction[] actions)
{
ArgumentNullException.ThrowIfNull(actions, nameof(actions));
Actions = actions;
}
```
Multiply arguments would all have checks at the top of constructor, and then code that sets the members.
Also I'm not sure "nameof" part is needed, as `ArgumentNullException.ThrowIfNull` provides automatic argument name detection, but that's a bit unrelated.
---
### Original Comments
#### Feedback Bot on 2/6/2026, 07:09 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
#### Hong Chee (Centific Technologies Inc) [MSFT] on 2/11/2026, 06:53 AM:
Thank you for taking the time to log this issue!
In order to investigate your issue further, can you help to confirm several questions?
- Did you see this issue only once or is it happening all the time?
- Which project type and language you use?
- Can you try to create a new simple solution and check if this issue also reproduces?
- Can you provide us a repro video using https://www.screentogif.com/ or a similar tool?
- Would it be possible to provide us sample file which can reproduce this issue?
- Could you try to update your VS to latest build?
(The reason we’re asking for additional information is that we’d like to fully understand the issue and try to reproduce it on our side.)
We look forward to hearing from you!
#### Person (2024-12-16 13:28:49Z) on 2/27/2026, 11:35 PM:
The issue is happening all the time. I use common SDK-styled csproj and C#. Here’s the repro sln/project/file: IssueRepro.zip
My VS is at the latest build atm of writing (18.3.2).
#### Person (2024-12-16 13:28:49Z) on 3/1/2026, 01:39 PM:
Looks like my prev comment didn’t count as “more info” for some reason. Look at it for “more info”.
#### Feedback Bot on 2/18/2026, 07:32 AM:
We will close this report in 14 days because we don’t have enough information to investigate further. To keep the problem open, please provide the requested details.
#### Hong Chee (Centific Technologies Inc) [MSFT] on 3/6/2026, 08:41 AM:

Thanks for your sharing the detail steps, I can reproduce this issue through your shared steps in VS community 2026 (18.2.1)and this issue has been escalated for further investigation, if there is any process, I will inform you immediately.
Contributor guide
Research direction
Start by reproducing the Generate constructor from members action in a C# project with Add null checks enabled, using the supplied repro project if needed. Trace the Roslyn/Visual Studio entry point for this refactoring and locate its existing tests. Done means generated constructors use the requested ArgumentNullException.ThrowIfNull pattern, including behavior for multiple parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100