Hi,
I get an InvalidProgramException when I use init properties in records. All my projects are in .Net 5 and the tests are running with other test runners.
In the past this problem has actually been solved, but with version 4.9.0.8 this exception is thrown again.
Can you help?
Build/Test Issues
InvalidOperationException with init properties again (.NET 5)
Started by unkown_dev on 2,139 views
Remco NCrunch Developer
#15628
28 Aug 2021 01:13 UTC
Hi, thanks for sharing this issue.
Are you able to isolate this in a self-contained sample solution that you can share with me? You can upload small solutions in ZIP form through the NCrunch contact form.
Are you able to isolate this in a self-contained sample solution that you can share with me? You can upload small solutions in ZIP form through the NCrunch contact form.
Hi,
Unfortunately, I cannot create a self-contained sample solution because I cannot reproduce the error in a sample solution.
I'll try to describe my problem. I have a test and i create a new record object "var test = new MyRecord {Name =" test ", Length = 4}" in this test and NCrunch throws this exception:
I tried to find the error and i found another "record" in my code with a DateTime property and when I changed the property from {get; init;} to {get; set;} - the test passed.
But this record was not covered by my test and I could not reproduce this case in the sample solution.
I suspect that the error message is incorrect or incomplete.
It's a pretty strange problem and I hope this description may help you.
Unfortunately, I cannot create a self-contained sample solution because I cannot reproduce the error in a sample solution.
I'll try to describe my problem. I have a test and i create a new record object "var test = new MyRecord {Name =" test ", Length = 4}" in this test and NCrunch throws this exception:
System.InvalidProgramException: Common Language Runtime detected an invalid program.
at MyRecord.set_Length (Int64 value)
at TestClass () in: line 367
at Xunit.Sdk.TestInvoker`1. <> c__DisplayClass48_1. <<InvokeTestMethodAsync> b__1> d.MoveNext () in C: \ Dev \ xunit \ xunit \ src \ xunit.execution \ Sdk \ Frameworks \ Runners \ TestInvoker.cs: line 264
--- End of stack trace from previous location ---
at Xunit.Sdk.ExecutionTimer.AggregateAsync (Func`1 asyncAction) in C: \ Dev \ xunit \ xunit \ src \ xunit.execution \ Sdk \ Frameworks \ ExecutionTimer.cs: line 48
at Xunit.Sdk.ExceptionAggregator.RunAsync (Func`1 code) in C: \ Dev \ xunit \ xunit \ src \ xunit.core \ Sdk \ ExceptionAggregator.cs: line 90
I tried to find the error and i found another "record" in my code with a DateTime property and when I changed the property from {get; init;} to {get; set;} - the test passed.
But this record was not covered by my test and I could not reproduce this case in the sample solution.
I suspect that the error message is incorrect or incomplete.
It's a pretty strange problem and I hope this description may help you.
Remco NCrunch Developer
#15630
31 Aug 2021 00:24 UTC
Thanks for these extra details.
Sometimes we can reproduce issues based on their description and no code sample is necessary. Unfortunately, in this case, we definitely need to be provided with a sample that can consistently produce the problem to have any hope of fixing it.
My suspicion is that there is likely to be a variation of some kind in your scenario that is triggering this issue (in addition to the use of the new language feature).
Things to check:
- Other toolsets (source generators, IL injectors or manipulators, AOP tools) could be involved
- Check for preview versions of .NET that might be getting pulled in. Do you have VS2022 installed or .NET6 installed?
- NuGet dependencies to complex packages, especially those involving build steps
Things that may allow you to work around the problem:
- Try using code coverage suppression comments around the code in question (i.e. //ncrunch: no coverage start)
- Try setting the 'Instrument output assembly' setting to false (will degrade feature-set)
- Try targeting your test project to a different version of .NET
Sometimes we can reproduce issues based on their description and no code sample is necessary. Unfortunately, in this case, we definitely need to be provided with a sample that can consistently produce the problem to have any hope of fixing it.
My suspicion is that there is likely to be a variation of some kind in your scenario that is triggering this issue (in addition to the use of the new language feature).
Things to check:
- Other toolsets (source generators, IL injectors or manipulators, AOP tools) could be involved
- Check for preview versions of .NET that might be getting pulled in. Do you have VS2022 installed or .NET6 installed?
- NuGet dependencies to complex packages, especially those involving build steps
Things that may allow you to work around the problem:
- Try using code coverage suppression comments around the code in question (i.e. //ncrunch: no coverage start)
- Try setting the 'Instrument output assembly' setting to false (will degrade feature-set)
- Try targeting your test project to a different version of .NET
Thanks for your tips
Setting the 'Instrument Output Assembly' setting to false fixed my problem.
My development environment:
I'm using the VS2022 Preview but had the same problem with VS2019. Resharper and Ncrunch are my only extensions.
.NET6 is installed but .NET5 is in use. I don't have any NuGet dependencies that involve the build steps
I am very sorry that I cannot send you an example, I know that would help a lot, for me it is also very strange that I cannot reproduce this issue.
Thank you for your help :)
Setting the 'Instrument Output Assembly' setting to false fixed my problem.
My development environment:
I'm using the VS2022 Preview but had the same problem with VS2019. Resharper and Ncrunch are my only extensions.
.NET6 is installed but .NET5 is in use. I don't have any NuGet dependencies that involve the build steps
I am very sorry that I cannot send you an example, I know that would help a lot, for me it is also very strange that I cannot reproduce this issue.
Thank you for your help :)
Post a reply
Log in to reply.