Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -56,7 +57,11 @@ internal string ToString(bool typed)

if (ArgumentType.IsArray)
{
#if !MONO
IList<CustomAttributeTypedArgument> array = (IList<CustomAttributeTypedArgument>)Value!;
Copy link
Member

@jkotas jkotas Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Value is documented to return ReadOnlyCollection<CustomAttributeTypedArgument> for arrays: https://learn.microsoft.com/en-us/dotnet/api/system.reflection.customattributetypedargument.value?view=net-9.0#remarks

Should this issue be fixed in the implementation of Value property on Mono instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas I couldn't figure out where to change the implementation of Value. Could you maybe help me point to it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect that the fix is needed in ves_icall_System_Reflection_RuntimeCustomAttributeData_ResolveArgumentsInternal or one of the methods that it calls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have assigned this to copilot: #119293. Let's see whether it can figure it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can take a look at the commits in #119293 for some inspiration where to fix this. (The changes in that PR are not quite right - if nothing else the changes in the shared code need to be under MONO ifdef.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas I can't seem to figure out a way to get this working. The change makes mono crash irrespective of whether I do it in the C# code or C code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas Can we make the code under a MONO ifdef?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix should be fixing the implementation of Value property to follow the documented behavior.

I am ok with some under MONO ifdef if there is no better way.

#else
IList array = (IList)Value!;
#endif
Type elementType = ArgumentType.GetElementType()!;

var result = new ValueStringBuilder(stackalloc char[256]);
Expand All @@ -73,7 +78,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(" }");
Expand Down
Loading