From 85f1e0aa49fb5fff2bb174ace9ed907112f3dec9 Mon Sep 17 00:00:00 2001 From: Venkad000 <20pt38@psgtech.ac.in> Date: Tue, 19 Aug 2025 07:56:26 +0000 Subject: [PATCH 1/3] closes: #118568 This is due to the difference in the way the constructorArguments are structured in Mono and CoreCLR which allows (IEnumerable)arg.Value).Cast() to be done in CoreCLR but not on Mono. This throws a "System.InvalidCastException: Specified cast is not valid" on Mono. --- .../CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index 1100c6c32886d..71b57e6581308 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -12325,7 +12325,9 @@ unsafe class C { } verifier.VerifyDiagnostics(); } - [Theory, CombinatorialData, WorkItem(65594, "https://github.com/dotnet/roslyn/issues/65594")] + [ConditionalTheory(typeof(NotOnAnyMono), Reason = "https://github.com/dotnet/runtime/issues/118568")] + [CombinatorialData] + [WorkItem(65594, "https://github.com/dotnet/roslyn/issues/65594")] public void Attribute_TypedParamsConstant_EnumArray_ConstructorArgument( [CombinatorialValues("class", "struct")] string kind, [CombinatorialValues("[]{}", "()")] string initializer) From 9c8b385e622b419625c8cf781673c2438fa93d3b Mon Sep 17 00:00:00 2001 From: Venkad000 <20pt38@psgtech.ac.in> Date: Tue, 19 Aug 2025 18:44:27 +0000 Subject: [PATCH 2/3] Changing the test so it works on Mono --- .../Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index 71b57e6581308..a392957e3210d 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -12325,22 +12325,22 @@ unsafe class C { } verifier.VerifyDiagnostics(); } - [ConditionalTheory(typeof(NotOnAnyMono), Reason = "https://github.com/dotnet/runtime/issues/118568")] - [CombinatorialData] - [WorkItem(65594, "https://github.com/dotnet/roslyn/issues/65594")] + [Theory, CombinatorialData, WorkItem(65594, "https://github.com/dotnet/roslyn/issues/65594"), WorkItem("https://github.com/dotnet/runtime/issues/118568")] public void Attribute_TypedParamsConstant_EnumArray_ConstructorArgument( [CombinatorialValues("class", "struct")] string kind, [CombinatorialValues("[]{}", "()")] string initializer) { + var EvalString = ExecutionConditionUtil.IsMonoCore ? "Console.WriteLine(((((IEnumerable)arg.Value).Cast().SingleOrDefault())) ?? \"null\");" : "Console.WriteLine(((IEnumerable)arg.Value).Cast().SingleOrDefault().Value ?? \"null\");"; + var IncludeString = ExecutionConditionUtil.IsMonoCore ? "" : "using System.Reflection;"; var source = $$""" using System; using System.Collections; using System.Linq; - using System.Reflection; + {{IncludeString}} var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType == typeof(A)); var arg = attr.ConstructorArguments.Single(); - Console.WriteLine(((IEnumerable)arg.Value).Cast().SingleOrDefault().Value ?? "null"); + {{EvalString}} class A : Attribute { From b50124ac1e571e15abe6a61e9d57ec83d174536a Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Wed, 20 Aug 2025 09:45:35 +0200 Subject: [PATCH 3/3] Improve code style --- .../Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index a392957e3210d..a86ab7c342676 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -12330,17 +12330,19 @@ public void Attribute_TypedParamsConstant_EnumArray_ConstructorArgument( [CombinatorialValues("class", "struct")] string kind, [CombinatorialValues("[]{}", "()")] string initializer) { - var EvalString = ExecutionConditionUtil.IsMonoCore ? "Console.WriteLine(((((IEnumerable)arg.Value).Cast().SingleOrDefault())) ?? \"null\");" : "Console.WriteLine(((IEnumerable)arg.Value).Cast().SingleOrDefault().Value ?? \"null\");"; - var IncludeString = ExecutionConditionUtil.IsMonoCore ? "" : "using System.Reflection;"; + var evalString = ExecutionConditionUtil.IsMonoCore + ? "Console.WriteLine(((((IEnumerable)arg.Value).Cast().SingleOrDefault())) ?? \"null\");" + : "Console.WriteLine(((IEnumerable)arg.Value).Cast().SingleOrDefault().Value ?? \"null\");"; + var includeString = ExecutionConditionUtil.IsMonoCore ? "" : "using System.Reflection;"; var source = $$""" using System; using System.Collections; using System.Linq; - {{IncludeString}} + {{includeString}} var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType == typeof(A)); var arg = attr.ConstructorArguments.Single(); - {{EvalString}} + {{evalString}} class A : Attribute {