dotnet / dotnet/roslyn

nameof for record Constructor Parameter not working

Open
#79,362 0 comments 1 reaction 1 assignee Claimed by @RikkiGibson View on GitHub
Area-Compilers
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**: .net9 latest

**Steps to Reproduce**:

i have this record and want to tell the compiler that TestString is not null when the boolean is true.

I get an error that TestString does not exist in the current context

```c#
public record Test(string? TestString, [property: MemberNotNullWhen(true, nameof(TestString))]bool IsTestString);
```

switchting to

```c#
public record Test(string? TestString, [property: MemberNotNullWhen(true, "TestString"))]bool IsTestString);
```
works as expected

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.