From 1ecadf265e2e562d5ba5eeb8c59cab44caa82f26 Mon Sep 17 00:00:00 2001 From: Venkad000 <20pt38@psgtech.ac.in> Date: Thu, 21 Aug 2025 04:49:03 +0000 Subject: [PATCH 1/2] ToString() throws and exception on Mono The function ToString() only takes into consideration how CoreClr's CustomAttributeTypedArgument is implemented and does a cast accordingly which causes it to fail with an InvalidCastException on Mono. So the casts should be runtime specific for it to not throw an InvalidCastException. --- .../src/System/Reflection/CustomAttributeTypedArgument.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs index e91941fc4df3a9..82ccdab3ba0d19 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs @@ -56,7 +56,11 @@ internal string ToString(bool typed) if (ArgumentType.IsArray) { +#if !MONO IList array = (IList)Value!; +#else + IList array = (IList)Value!; +#endif Type elementType = ArgumentType.GetElementType()!; var result = new ValueStringBuilder(stackalloc char[256]); @@ -73,7 +77,11 @@ internal string ToString(bool typed) { result.Append(", "); } +#if !MONO result.Append(array[i].ToString(elementType != typeof(object))); +#else + result.Append(array[i]!.ToString()); +#endif } result.Append(" }"); From b10a8aa5a3515ae323d845c9db15207a7c0d6cd8 Mon Sep 17 00:00:00 2001 From: Venkad000 <20pt38@psgtech.ac.in> Date: Thu, 21 Aug 2025 05:27:13 +0000 Subject: [PATCH 2/2] Added missing headerfile --- .../src/System/Reflection/CustomAttributeTypedArgument.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs index 82ccdab3ba0d19..8e6324f24ad994 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text;