Build/Test Issues

Notsupportedexception when building a project with source generators

Started by erwinvandervalk on 2,022 views

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:

<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:
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

Edited

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.
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!
Would you be interested in trying the build below? It contains a fix to introduce support for generic custom attributes.

NCrunch_Console_4.16.0.1.msi
NCrunch_Console_4.16.0.1.zip
NCrunch_GridNodeServer_4.16.0.1.msi
NCrunch_GridNodeServer_4.16.0.1.zip
NCrunch_LicenseServer_4.16.0.1.zip
NCrunch_VS2010_4.16.0.1.msi
NCrunch_VS2010_4.16.0.1.zip
NCrunch_VS2012_4.16.0.1.msi
NCrunch_VS2012_4.16.0.1.zip
NCrunch_VS2013_4.16.0.1.msi
NCrunch_VS2013_4.16.0.1.zip
NCrunch_VS2015_4.16.0.1.msi
NCrunch_VS2015_4.16.0.1.msi.7z
NCrunch_VS2015_4.16.0.1.zip
NCrunch_VS2017_4.16.0.1.msi
NCrunch_VS2017_4.16.0.1.msi.7z
NCrunch_VS2017_4.16.0.1.zip
NCrunch_VS2019_4.16.0.1.msi
NCrunch_VS2019_4.16.0.1.msi.7z
NCrunch_VS2019_4.16.0.1.zip
NCrunch_VS2022_4.16.0.1.msi
NCrunch_VS2022_4.16.0.1.msi.7z
NCrunch_VS2022_4.16.0.1.zip

Post a reply

Log in to reply.