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

Notification

Icon
Error

Unable to hash type 'Code' due to exception: System.NotSupportedException: Unknown element type: Var
anderswg
#1 Posted : Friday, November 17, 2023 12:08:41 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/8/2017(UTC)
Posts: 3
Location: Norway

Was thanked: 1 time(s) in 1 post(s)
Hi, im getting this error when running tests on code with generic attributes



Code:
Quote:

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)

Remco
#2 Posted : Friday, November 17, 2023 12:39:20 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, thanks for sharing this issue.

I've reproduced it as described and will update you when we have a solution available.
Remco
#3 Posted : Wednesday, November 22, 2023 2:46:50 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)
anderswg
#4 Posted : Wednesday, November 22, 2023 7:58:24 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/8/2017(UTC)
Posts: 3
Location: Norway

Was thanked: 1 time(s) in 1 post(s)
Hi, and thanks for the build.
Im getting another exception in the same example now

Quote:
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)
Remco
#5 Posted : Wednesday, November 22, 2023 11:32:23 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)
anderswg
#6 Posted : Thursday, November 23, 2023 9:52:03 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/8/2017(UTC)
Posts: 3
Location: Norway

Was thanked: 1 time(s) in 1 post(s)
Hi, this works now

Thanks again
1 user thanked anderswg for this useful post.
Remco on 11/23/2023(UTC)
jxnnik
#7 Posted : Monday, January 22, 2024 12:42:11 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/22/2024(UTC)
Posts: 3
Location: Germany

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
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):

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

Quote:
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.
NeilMacMullen
#8 Posted : Monday, January 22, 2024 3:53:03 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 12/15/2016(UTC)
Posts: 55
Location: United Kingdom

Thanks: 29 times
Was thanked: 12 time(s) in 11 post(s)
Unfortunately we're also experiencing this issue (still present with 4.19.08, VS2022).
Remco
#9 Posted : Monday, January 22, 2024 10:56:32 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)
Thanks for reporting this. I'll take a look and will get back to you.
Remco
#10 Posted : Tuesday, January 23, 2024 7:24:26 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)
1 user thanked Remco for this useful post.
jxnnik on 1/23/2024(UTC)
jxnnik
#11 Posted : Tuesday, January 23, 2024 8:35:35 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/22/2024(UTC)
Posts: 3
Location: Germany

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
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:
Code:
[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:
Code:
[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; }
}


Quote:
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)
Remco
#12 Posted : Tuesday, January 23, 2024 12:30:10 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)
1 user thanked Remco for this useful post.
jxnnik on 1/23/2024(UTC)
jxnnik
#13 Posted : Tuesday, January 23, 2024 1:04:23 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/22/2024(UTC)
Posts: 3
Location: Germany

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
That fixed the problem! Thank you very much.
1 user thanked jxnnik for this useful post.
Remco on 1/23/2024(UTC)
NeilMacMullen
#14 Posted : Thursday, January 25, 2024 11:22:04 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 12/15/2016(UTC)
Posts: 55
Location: United Kingdom

Thanks: 29 times
Was thanked: 12 time(s) in 11 post(s)
Great job - thanks !
Users browsing this topic
Guest (2)
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.163 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download