Skip to content

Assert.ThrowsExactly: ambiguity between Assert.ThrowsExactly<TException>(Func<object?>, string, params object[]) and Assert.ThrowsExactly<TException>(Action, ref Assert.AssertThrowsExactlyInterpolatedStringHandler<TException>) #6152

@LukasGelke

Description

@LukasGelke

Describe the bug

previously working code is not compiling anymore.

Steps To Reproduce

  1. have a test project with net471 and net8.0
  2. have a Test Method a la:
  public void RunTest()
  {
    int x = 1;
    Assert.ThrowsExactly<DivideByZeroException>(() => GetValue(x), $"{x}"); // CS0121
    Assert.Throws<DivideByZeroException>(() => GetValue(x), $"{x}");            // OK
    static object GetValue(int x) => x;
  }
  1. upgrade NuGet MsTest from 3.8.3 to 3.9.3

Expected behavior

  • solution/project compiles as before

Actual behavior

  • does not compile
  • need to add explicit cast/ new Action(..) to resolve

Additional context

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions