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

Notification

Icon
Error

Notsupportedexception when building a project with source generators
erwinvandervalk
#1 Posted : Tuesday, December 13, 2022 8:02:54 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/23/2019(UTC)
Posts: 3
Location: Netherlands

Was thanked: 2 time(s) in 2 post(s)
Hi,

I'm getting an exception when I build a project that uses source generators. Is there a workaround for this that might help us?

Here's the exception that we're getting.

NCrunch has encountered an internal error: System.Exception: nCrunch.Compiler.StaticManipulation.CilTypeHashException: Unable to hash type 'TestProject2.EnvironmentName' due to exception: System.NotSupportedException: TypeSpec
at nCrunch.Compiler.Cil.Methods.CilMemberReference.GetReferencedTypeImpactId()
at nCrunch.Compiler.Cil.CustomAttributes.CilCustomAttribute..(CilMemberReference )
at nCrunch.Compiler.Cil.CustomAttributes.CilCustomAttribute.[T](Func`2 , Func`2 )
at nCrunch.Compiler.Cil.CustomAttributes.CilSortedCustomAttributeEnumerator.MoveNext()
at nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.HashType(FNV64& hash, CilTypeDefinition type)
at nCrunch.Compiler.StaticManipulation.BuiltCilAssembly.ExtractClassMethodData(TestFrameworkDescription[] applicableTestFrameworks, IDictionary`2 codeFileIDsByForegroundFilePath, Boolean storeImpactHashes)
at nCrunch.Compiler.StaticManipulation.BuiltCilAssembly.ExtractClassMethodData(TestFrameworkDescription[] applicableTestFrameworks, IDictionary`2 codeFileIDsByForegroundFilePath, Boolean storeImpactHashes)
at nCrunch.Compiler.CilProcessingTasks.CilMethodHashingTask..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Compiler.CilProcessingTasks.ConcurrentCilTaskProcessor.()
at nCrunch.Compiler.CilProcessingTasks.ConcurrentCilTaskProcessor.ProcessTasks(Int32 backgroundThreadsAllowed)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentInstrumentationParameters , BuildOutput , IBackgroundTaskProcessor )
at nCrunch.Compiler.RemoteBuildRunner.PerformPostProcessingOfBuiltAssembly(ComponentInstrumentationParameters instrumentationParameters, BuildOutput output, IBackgroundTaskProcessor backgroundTaskProcessor)
at nCrunch.Core.BuildManagement.BuildEnvironment..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Core.BuildManagement.BuildEnvironment.Build(SnapshotComponent snapshotComponentToBuild, IList`1 referencedComponents, GridClientId gridClientId, IList`1 customEnvironmentVariables, IPlatformBuildExtender extender, Guid taskId, GridAddress clientAddress, Boolean extractCoverageReportStructure)


I have a small repro.

In the repro, i'm using a library called Radix.Generators, which (amongst other things) can generate some code for value objects.

csproj:
Code:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
    <PackageReference Include="xunit" Version="2.4.2" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.1.2">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Radix" Version="1.0.10" />
    <PackageReference Include="Radix.Generators" Version="1.0.10" />

  </ItemGroup>

</Project>


Here's the test:
Code:
namespace TestProject2
{
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {
            var envName = EnvironmentName.Create("some name");
        }
    }

    [Validated<string, Radix.Data.String.Validity.IsNotNullEmptyOrWhiteSpace>]
    public readonly partial record struct EnvironmentName { }


}


Thanks for any support :)

Kind regards,
erwin
Remco
#2 Posted : Tuesday, December 13, 2022 10:57:36 PM(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 Erwin,

Thanks for sharing this issue.

This problem is caused by a change MS introduced to the .NET assembly structure in the version of VS released two weeks ago (which enabled generics on custom attributes under C# 11). NCrunch needs a small update to support this new feature.

We're working on this now and I will update you with a build as soon as it becomes available.
erwinvandervalk
#3 Posted : Wednesday, December 14, 2022 6:51:11 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/23/2019(UTC)
Posts: 3
Location: Netherlands

Was thanked: 2 time(s) in 2 post(s)
Hi Remco,

Thanks for looking into this.

Looking forward to the next update then.

With kind regards,
Erwin

Ps, thanks for creating such a nice tool!
1 user thanked erwinvandervalk for this useful post.
Remco on 12/14/2022(UTC)
Remco
#4 Posted : Wednesday, December 14, 2022 10:19:15 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)
erwinvandervalk
#5 Posted : Thursday, December 15, 2022 1:25:56 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/23/2019(UTC)
Posts: 3
Location: Netherlands

Was thanked: 2 time(s) in 2 post(s)
Yes, that fixes it
1 user thanked erwinvandervalk for this useful post.
Remco on 12/15/2022(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.056 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download