Instrumenting C# 9 init-only property produces invalid assembly
hell-racer opened this issue · 4 comments
Hi!
I have a test class with an init-only property (C# 9).
I'm unable to generate code coverage, because the test fails at runtime.
I use net5.0.
Consider the following minimalistic example:
public class MinicoverTests
{
[Fact]
public void InitPropertySet()
{
TestClass test = new() { Property = "test" };
}
public class TestClass
{
public string Property { get; init; }
}
}
When I try to run tests after instrumenting assemblies, I get the following output:
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:01.19] MyNameSpace.MinicoverTests.InitPropertySet [FAIL]
Failed MyNameSpace.MinicoverTests.InitPropertySet [2 ms]
Error Message:
System.InvalidProgramException : Common Language Runtime detected an invalid program.
Stack Trace:
at MyNameSpace.MinicoverTests.TestClass.set_Property(String value)
at MyNameSpace.MinicoverTests.InitPropertySet()
Failed! - Failed: 1, Passed: 0, Skipped: 0, Total: 1, Duration: < 1 ms
If I change accessor method for property Property
from init
to set
, it runs correctly.
The test runs fine without instrumentation too.
Thanks!
Which version of Minicover are you using?
I'm using 3.4.7 (also tried several previous versions).
@ffMathy can you create new release?
Yup, sorry about that. This is not my repo initially, so still getting used to the process here.
I created a release now. Should run via Azure Pipelines, and then push a release soon.