Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

InvalidOperationException with init properties again (.NET 5)
unkown_dev
#1 Posted : Friday, August 27, 2021 1:13:38 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/27/2021(UTC)
Posts: 3
Location: Germany

Thanks: 1 times
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?
Remco
#2 Posted : Saturday, August 28, 2021 1:13:07 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
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.
unkown_dev
#3 Posted : Monday, August 30, 2021 2:25:21 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/27/2021(UTC)
Posts: 3
Location: Germany

Thanks: 1 times
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:
Quote:
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
#4 Posted : Tuesday, August 31, 2021 12:24:52 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
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
1 user thanked Remco for this useful post.
unkown_dev on 8/31/2021(UTC)
unkown_dev
#5 Posted : Tuesday, August 31, 2021 8:20:05 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/27/2021(UTC)
Posts: 3
Location: Germany

Thanks: 1 times
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 :)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.048 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download