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

Notification

Icon
Error

.NET8 Preview 7
dandcg
#1 Posted : Sunday, August 27, 2023 9:39:05 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/2/2022(UTC)
Posts: 1
Location: United Kingdom

Hi,

I have a dotnet8 preview 7 project and its failing to build in crunch.

Test project error:

System.Exception: An exception was thrown in the remote environment: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> nCrunch.Common.UserException: Errors occurred while trying to load the project file:
The current .NET SDK does not support targeting .NET 8.0. Either target .NET 7.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. Download the .NET SDK from https://aka.ms/dotnet/download

Class project error:

System.Exception: An exception was thrown in the remote environment: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> nCrunch.Common.UserException: Errors occurred while trying to load the project file: #
The FrameworkReference 'Microsoft.NETCore.App' was not recognized


Any ideas?

Dan
Remco
#2 Posted : Sunday, August 27, 2023 11:04:36 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 952 times
Was thanked: 1280 time(s) in 1187 post(s)
Hi Dan,

Thanks for sharing this issue.

As this platform is still in a preview state, we haven't done any work yet to get NCrunch running on .NET8. We'll be posting an update to address any issues when the platform is fully released.
Remco
#4 Posted : Saturday, October 28, 2023 8:21:52 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 952 times
Was thanked: 1280 time(s) in 1187 post(s)
I've looking into .NET 8 support now under NCrunch, as it's reached RC status and looks ready to drop soon.

The good news is that at a cursory glance, it seems that the builds of NCrunch we have out right now can probably already handle .NET 8. The error being kicked up here is caused by NCrunch not resolving to preview SDKs when it tries to build the project.

You can actually override this behaviour using a couple of environment variables to tell NCrunch the install path and version of the SDK you want to use. Check your Program Files\dotnet\sdk directory to see which versions of the SDK you have installed, then use NCrunch's 'Custom environment variables' setting to specify two environment variables, such as:

DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR = C:\Program Files\dotnet\sdk\8.0.100-rc.2.23502.2\Sdks
DOTNET_MSBUILD_SDK_RESOLVER_SDKS_VER = 8.0.100-rc.2.23502.2

I'm hopeful this is all we need to do to be able to work with .NET 8. Note that when .NET 8 reaches RTM, it will no longer be considered a preview SDK and all recently released versions of NCrunch should resolve to it automatically.

If you find anything else we aren't handling in .NET 8, please do share this here and we'll se what we can do to get things fixed.
zeko77
#5 Posted : Wednesday, November 29, 2023 6:58:10 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/1/2023(UTC)
Posts: 3
Location: Bosnia and Herzegovina

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
The only issue I am experiencing now is that record data types are marked with black No covering tests marker.
Remco
#6 Posted : Wednesday, November 29, 2023 9:02:38 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 952 times
Was thanked: 1280 time(s) in 1187 post(s)
zeko77;16942 wrote:
The only issue I am experiencing now is that record data types are marked with black No covering tests marker.


Thanks for sharing this.

I've taken a look at this issue and determined that there isn't much we can practically do about it, as the problem isn't in NCrunch.

The record types are largely compiler generated structures. Inside the IL structure there is a secondary constructor that is used for cloning instances of the type when the new 'with' keyword is used. For reasons unknown, the compiler chooses to represent a single line of code in this constructor as having an actual sequence point in the PDB. You'll find that if you use the 'with' keyword on the type, it's actually possible to have the runtime execute this line of code and it will be marked as covered by NCrunch. You can also hit it with a breakpoint using the debugger.

It is technically possible for us to try and implement something that would suppress specific sequence points when processing PDBs, but this is not without cost. Adding special exceptions to coverage tracking reduces the performance of NCrunch's instrumentation and it increases the risk of things going wrong or breaking in future. It does also run counter to NCrunch's goal of reporting what is actually happening in the runtime rather than in our fabricated viewpoint of it.

If the black dot is an issue, I recommend writing a test to exercise the cloning of the structure using the 'with' keyword.
1 user thanked Remco for this useful post.
zeko77 on 11/29/2023(UTC)
zeko77
#7 Posted : Wednesday, November 29, 2023 9:22:55 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/1/2023(UTC)
Posts: 3
Location: Bosnia and Herzegovina

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Thank you for fast response. It is an issue only because it messes with code coverage. I will try the test-with approach.
Keep up the great work. NCrunch really rocks.
zeko77
#9 Posted : Wednesday, November 29, 2023 1:38:27 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/1/2023(UTC)
Posts: 3
Location: Bosnia and Herzegovina

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
For anyone intersted, this is the workaround using reflection.

Code:

public class NCrunchRecordHack
{
    [Fact]
    public void Should_invoke_secondary_constructor()
    {
        var a = Assembly.GetAssembly(typeof(SomeRecordType));
       Type[] types = a.GetTypes().Where(type => IsRecord(type) && !type.IsAbstract).ToArray();
        foreach (var type in types)
            InvokeCloningMethod(type);
    }
    static void InvokeCloningMethod(Type type)
    {
        var instance = Activator.CreateInstance(type);
        var m = type.GetMethod(("<Clone>$"));
        m.Invoke(instance, null);
    }

    public static bool IsRecord(Type type) => type.GetMethod("<Clone>$") != null;
}
1 user thanked zeko77 for this useful post.
Remco on 11/29/2023(UTC)
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.047 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download