Version Used:
.NET SDK:
Version: 6.0.100
Commit: 9e8b04bbff
Steps to Reproduce:
- Create a record struct with a parameter list with at least two parameters:
public record struct S(char First, char Second)
{
}
- Add a constructor that takes a parameter of some type (the exact type seems to not matter):
public record struct S(char First, char Second)
{
public S(object o)
{
}
}
- This produces CS8862: A constructor declared in a record with parameter list must have 'this' constructor initializer, which is expected. To fix this error, add a call to the default constructor:
public record struct S(char First, char Second)
{
public S(object o) : this()
{
}
}
- Attempt to create an instance of the struct:
var s = new S(new object());
Console.WriteLine(s);
Expected Behavior:
The struct is created and printed with First and Second set to default(char).
Actual Behavior:
A System.InvalidProgramException is thrown during execution:
Unhandled exception. System.InvalidProgramException: Common Language Runtime detected an invalid program.
at S..ctor(Object o)
at Program.<Main>$(String[] args) in D:\<path_ommited>\Program.cs:line 1
Full code:
Occurs both when running compiled to Debug and Release.
var s = new S(new object());
System.Console.WriteLine(s);
public record struct S(char First, char Second)
{
public S(object o) : this()
{
}
}
https://dotnetfiddle.net/85o0Th
Version Used:
.NET SDK:
Version: 6.0.100
Commit: 9e8b04bbff
Steps to Reproduce:
Expected Behavior:
The struct is created and printed with
FirstandSecondset todefault(char).Actual Behavior:
A
System.InvalidProgramExceptionis thrown during execution:Full code:
Occurs both when running compiled to Debug and Release.
https://dotnetfiddle.net/85o0Th