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 NCrunch Developer
#16820
27 Aug 2023 23:04 UTC
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.
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.
Deleted post
#16869
11 Sep 2023 12:11 UTC
Remco NCrunch Developer
#16894
28 Oct 2023 08:21 UTC
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.
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.
The only issue I am experiencing now is that record data types are marked with black No covering tests marker.
Remco NCrunch Developer
#16943
29 Nov 2023 09:02 UTC
zeko77 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.
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.
Keep up the great work. NCrunch really rocks.
For anyone intersted, this is the workaround using reflection.
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;
}
Edited 29 Nov 2023 13:43 UTC
Deleted post
#17408
07 Jun 2024 14:09 UTC
Deleted post
#17411
11 Jun 2024 06:55 UTC
Deleted post
#17429
22 Jun 2024 05:52 UTC
Deleted post
#17584
06 Sep 2024 06:03 UTC
Deleted post
#17682
18 Oct 2024 11:13 UTC
Deleted post
#18044
14 Apr 2025 08:53 UTC
Deleted post
#18247
25 Jul 2025 07:25 UTC
Post a reply
Log in to reply.