Build/Test Issues

Unable to hash type 'Code' due to exception: System.NotSupportedException: Unknown element type: Var

Started by anderswg on 3,688 views

Hi, im getting this error when running tests on code with generic attributes



Code:

using Microsoft.VisualStudio.TestTools.UnitTesting;


[MyAttribute<MyEnum>(MyEnum.One)]
public class Code
{

}

public class MyAttribute<T> : Attribute where T : Enum
{
public MyAttribute(T value)
{

}
}

public enum MyEnum
{
One
}


[TestClass]
public class CodeTests
{
[TestMethod]
public void Test()
{
var code = new Code();
}
}



Full error:
NCrunch has encountered an internal error: System.Exception: nCrunch.Compiler.StaticManipulation.CilTypeHashException: Unable to hash type 'Code' due to exception: System.NotSupportedException: Unknown element type: Var
at nCrunch.Compiler.Cil.CustomAttributes.CilAttributeArgument.get_SizeInBytes()
at nCrunch.Compiler.Cil.CustomAttributes.CilCustomAttributeValue.get_NamedArguments()
at nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.HashCustomAttribute(FNV64& hash, CilCustomAttribute customAttribute)
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, GridClientDescription clientDescription, Boolean extractCoverageReportStructure)

Hi, thanks for sharing this issue.

I've reproduced it as described and will update you when we have a solution available.
Would you be interested in trying the build below?

NCrunch_Console_4.19.0.7.msi
NCrunch_Console_4.19.0.7.zip
NCrunch_GridNodeServer_4.19.0.7.msi
NCrunch_GridNodeServer_4.19.0.7.zip
NCrunch_LicenseServer_4.19.0.7.zip
NCrunch_VS2010_4.19.0.7.msi
NCrunch_VS2010_4.19.0.7.zip
NCrunch_VS2012_4.19.0.7.msi
NCrunch_VS2012_4.19.0.7.zip
NCrunch_VS2013_4.19.0.7.msi
NCrunch_VS2013_4.19.0.7.zip
NCrunch_VS2015_4.19.0.7.msi
NCrunch_VS2015_4.19.0.7.msi.7z
NCrunch_VS2015_4.19.0.7.zip
NCrunch_VS2017_4.19.0.7.msi
NCrunch_VS2017_4.19.0.7.msi.7z
NCrunch_VS2017_4.19.0.7.zip
NCrunch_VS2019_4.19.0.7.msi
NCrunch_VS2019_4.19.0.7.msi.7z
NCrunch_VS2019_4.19.0.7.zip
NCrunch_VS2022_4.19.0.7.msi
NCrunch_VS2022_4.19.0.7.msi.7z
NCrunch_VS2022_4.19.0.7.zip
Hi, and thanks for the build.
Im getting another exception in the same example now

NCrunch has encountered an internal error: System.Exception: nCrunch.Compiler.StaticManipulation.CilTypeHashException: Unable to hash type 'Code' due to exception: System.NotSupportedException: Unknown element type: Var
at nCrunch.Compiler.Cil.CustomAttributes.CilAttributeArgument.GetImpactHash()
at nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.HashCustomAttribute(FNV64& hash, CilCustomAttribute customAttribute)
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, GridClientDescription clientDescription, Boolean extractCoverageReportStructure)
My apologies. I fixed the immediate issue but should have confirmed the fix against the sample you provided.. if I'd done this I would have noticed the exact same problem showing up in a different place.

Would you mind trying the build below?

NCrunch_Console_4.19.0.8.msi
NCrunch_Console_4.19.0.8.zip
NCrunch_GridNodeServer_4.19.0.8.msi
NCrunch_GridNodeServer_4.19.0.8.zip
NCrunch_LicenseServer_4.19.0.8.zip
NCrunch_VS2010_4.19.0.8.msi
NCrunch_VS2010_4.19.0.8.zip
NCrunch_VS2012_4.19.0.8.msi
NCrunch_VS2012_4.19.0.8.zip
NCrunch_VS2013_4.19.0.8.msi
NCrunch_VS2013_4.19.0.8.zip
NCrunch_VS2015_4.19.0.8.msi
NCrunch_VS2015_4.19.0.8.msi.7z
NCrunch_VS2015_4.19.0.8.zip
NCrunch_VS2017_4.19.0.8.msi
NCrunch_VS2017_4.19.0.8.msi.7z
NCrunch_VS2017_4.19.0.8.zip
NCrunch_VS2019_4.19.0.8.msi
NCrunch_VS2019_4.19.0.8.msi.7z
NCrunch_VS2019_4.19.0.8.zip
NCrunch_VS2022_4.19.0.8.msi
NCrunch_VS2022_4.19.0.8.msi.7z
NCrunch_VS2022_4.19.0.8.zip
Hi, this works now

Thanks again
Hi together,

i've tried the provided version 4.19.0.8 in VS2022 but it still does not seem to work.

Here is a minimum example for reproducing the issue (same for .NET7 / 8):

[AttributeUsage(AttributeTargets.Property)]
public sealed class GenericAttribute<T> : Attribute
{
    public GenericAttribute(T instance)
    {
        Instance = instance;
    }
    
    public T Instance { get; set; }
}

public class TestClass
{

    [Generic<string>(@"asdf")]
    public string Test { get; set; }
}


This leads to the following stack trace:

NCrunch has encountered an internal error: System.Exception: nCrunch.Compiler.StaticManipulation.CilTypeHashException: Unable to hash type 'NcrunchTest.TestClass' due to exception: nCrunch.Compiler.StaticManipulation.CilHashException: Unable to hash method 'System.String NcrunchTest.TestClass::get_Test()' due to exception: System.NotSupportedException: Generic parameter number 97 could not be resolved in type signature: NcrunchTest.GenericAttribute`1[[System.String, System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]
bei nCrunch.Compiler.Cil.CustomAttributes.CilAttributeArgument.get_SizeInBytes()
bei nCrunch.Compiler.Cil.CustomAttributes.CilCustomAttributeValue.get_NamedArguments()
bei nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.HashCustomAttribute(FNV64& hash, CilCustomAttribute customAttribute)
bei nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.(FNV64& , CilMethodDefinition )
bei nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.HashMethod(CilMethodDefinition method, Int32 stackSize)
bei nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.HashMethod(CilMethodDefinition method, Int32 stackSize)
bei nCrunch.Compiler.StaticManipulation.BuiltCilAssembly.(Boolean , ClassMethodData , Dictionary`2 , CilTypeDefinition , FNV64& , CilMethodDefinition )
bei nCrunch.Compiler.StaticManipulation.BuiltCilAssembly.ExtractClassMethodData(TestFrameworkDescription[] applicableTestFrameworks, IDictionary`2 codeFileIDsByForegroundFilePath, Boolean storeImpactHashes)
bei nCrunch.Compiler.StaticManipulation.BuiltCilAssembly.ExtractClassMethodData(TestFrameworkDescription[] applicableTestFrameworks, IDictionary`2 codeFileIDsByForegroundFilePath, Boolean storeImpactHashes)
bei nCrunch.Compiler.CilProcessingTasks.CilMethodHashingTask..()
bei nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
bei nCrunch.Compiler.CilProcessingTasks.ConcurrentCilTaskProcessor.()
bei nCrunch.Compiler.CilProcessingTasks.ConcurrentCilTaskProcessor.ProcessTasks(Int32 backgroundThreadsAllowed)
bei nCrunch.Compiler.RemoteBuildRunner.(ComponentInstrumentationParameters , BuildOutput , IBackgroundTaskProcessor )
bei nCrunch.Compiler.RemoteBuildRunner.PerformPostProcessingOfBuiltAssembly(ComponentInstrumentationParameters instrumentationParameters, BuildOutput output, IBackgroundTaskProcessor backgroundTaskProcessor)
bei nCrunch.Core.BuildManagement.BuildEnvironment..()
bei nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
bei nCrunch.Core.BuildManagement.BuildEnvironment.Build(SnapshotComponent snapshotComponentToBuild, IList`1 referencedComponents, GridClientId gridClientId, IList`1 customEnvironmentVariables, IPlatformBuildExtender extender, Guid taskId, GridClientDescription clientDescription, Boolean extractCoverageReportStructure)


I hope this will help you to investigate the issue.

EDIT: I think this issue only appears with reference types as generic arguments. When working with value types only, everything works fine.

Edited

Unfortunately we're also experiencing this issue (still present with 4.19.08, VS2022).
Thanks for reporting this. I'll take a look and will get back to you.
Would you be interested in trying the build below to see if this solves the problem for you?

NCrunch_Console_4.19.0.9.msi
NCrunch_Console_4.19.0.9.zip
NCrunch_GridNodeServer_4.19.0.9.msi
NCrunch_GridNodeServer_4.19.0.9.zip
NCrunch_LicenseServer_4.19.0.9.zip
NCrunch_VS2010_4.19.0.9.msi
NCrunch_VS2010_4.19.0.9.zip
NCrunch_VS2012_4.19.0.9.msi
NCrunch_VS2012_4.19.0.9.zip
NCrunch_VS2013_4.19.0.9.msi
NCrunch_VS2013_4.19.0.9.zip
NCrunch_VS2015_4.19.0.9.msi
NCrunch_VS2015_4.19.0.9.msi.7z
NCrunch_VS2015_4.19.0.9.zip
NCrunch_VS2017_4.19.0.9.msi
NCrunch_VS2017_4.19.0.9.msi.7z
NCrunch_VS2017_4.19.0.9.zip
NCrunch_VS2019_4.19.0.9.msi
NCrunch_VS2019_4.19.0.9.msi.7z
NCrunch_VS2019_4.19.0.9.zip
NCrunch_VS2022_4.19.0.9.msi
NCrunch_VS2022_4.19.0.9.msi.7z
NCrunch_VS2022_4.19.0.9.zip
Thank you, that works for the basic example I provided!

However, in the acutal project the build still fails. I've included a new minimum example that still gives the same exception, when a generic constructor parameter is not the first argument.

This does work:
[AttributeUsage(AttributeTargets.Property)]
public sealed class GenericAttribute<T> : Attribute
{
    public GenericAttribute(T instance, string str1, string str2)
    {
        Instance = instance;
    }
    
    public T Instance { get; set; }
}

public class TestClass
{

    [Generic<string>("x", "y", "z")]
    public string Test { get; set; }
}


This does not work:
[AttributeUsage(AttributeTargets.Property)]
public sealed class GenericAttribute<T> : Attribute
{
    public GenericAttribute(string str1, string str2, T instance)
    {
        Instance = instance;
    }
    
    public T Instance { get; set; }
}

public class TestClass
{

    [Generic<string>("x", "y", "z")]
    public string Test { get; set; }
}


NCrunch has encountered an internal error: System.Exception: nCrunch.Compiler.StaticManipulation.CilTypeHashException: Unable to hash type 'NcrunchTest.TestClass' due to exception: nCrunch.Compiler.StaticManipulation.CilHashException: Unable to hash method 'System.String NcrunchTest.TestClass::get_Test()' due to exception: System.NotSupportedException: Generic parameter number 2 could not be resolved in type signature: NcrunchTest.GenericAttribute`1[[System.String, System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]
bei nCrunch.Compiler.Cil.CustomAttributes.CilAttributeArgument.()
bei nCrunch.Compiler.Cil.CustomAttributes.CilAttributeArgument.get_SizeInBytes()
bei nCrunch.Compiler.Cil.CustomAttributes.CilCustomAttributeValue.get_NamedArguments()
bei nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.HashCustomAttribute(FNV64& hash, CilCustomAttribute customAttribute)
bei nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.(FNV64& , CilMethodDefinition )
bei nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.HashMethod(CilMethodDefinition method, Int32 stackSize)
bei nCrunch.Compiler.StaticManipulation.CilMethodHashGenerator.HashMethod(CilMethodDefinition method, Int32 stackSize)
bei nCrunch.Compiler.StaticManipulation.BuiltCilAssembly.(Boolean , ClassMethodData , Dictionary`2 , CilTypeDefinition , FNV64& , CilMethodDefinition )
bei nCrunch.Compiler.StaticManipulation.BuiltCilAssembly.ExtractClassMethodData(TestFrameworkDescription[] applicableTestFrameworks, IDictionary`2 codeFileIDsByForegroundFilePath, Boolean storeImpactHashes)
bei nCrunch.Compiler.StaticManipulation.BuiltCilAssembly.ExtractClassMethodData(TestFrameworkDescription[] applicableTestFrameworks, IDictionary`2 codeFileIDsByForegroundFilePath, Boolean storeImpactHashes)
bei nCrunch.Compiler.CilProcessingTasks.CilMethodHashingTask..()
bei nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
bei nCrunch.Compiler.CilProcessingTasks.ConcurrentCilTaskProcessor.()
bei nCrunch.Compiler.CilProcessingTasks.ConcurrentCilTaskProcessor.ProcessTasks(Int32 backgroundThreadsAllowed)
bei nCrunch.Compiler.RemoteBuildRunner.(ComponentInstrumentationParameters , BuildOutput , IBackgroundTaskProcessor )
bei nCrunch.Compiler.RemoteBuildRunner.PerformPostProcessingOfBuiltAssembly(ComponentInstrumentationParameters instrumentationParameters, BuildOutput output, IBackgroundTaskProcessor backgroundTaskProcessor)
bei nCrunch.Core.BuildManagement.BuildEnvironment..()
bei nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
bei nCrunch.Core.BuildManagement.BuildEnvironment.Build(SnapshotComponent snapshotComponentToBuild, IList`1 referencedComponents, GridClientId gridClientId, IList`1 customEnvironmentVariables, IPlatformBuildExtender extender, Guid taskId, GridClientDescription clientDescription, Boolean extractCoverageReportStructure)
My apologies. I'm feeling more confident in the build below if you'd like to give it a try.

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

Edited

That fixed the problem! Thank you very much.

Post a reply

Log in to reply.