roslyn: Constructor with default parameter not found in using statement inside lambda containing a switch statement

Version Used: Microsoft Visual Studio Community 2017 Version 15.1 (26403.7) Release

Steps to Reproduce:

  1. Compile the following C# code:
using System;

public class Class2 : IDisposable
{
    public Class2(bool parameter = false)
    {
    }

    public void Dispose()
    {
    }
}

public class Class1
{
    public void Test()
    {
        var x = (Action<int>)(s =>
        {
            using (new Class2())
            {
                switch (0)
                {
                }
            }
        });
    }
}

Expected Behavior: The code compiles without errors.

Actual Behavior: The compiler generates the error: “CS1729 ‘Class2’ does not contain a constructor that takes that many arguments” on the line containing the “new Class2()” expression.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments