Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RawDefaultValue is resolved differently between runtimes #76174

Closed
ivanpovazan opened this issue Sep 26, 2022 · 6 comments
Closed

RawDefaultValue is resolved differently between runtimes #76174

ivanpovazan opened this issue Sep 26, 2022 · 6 comments

Comments

@ivanpovazan
Copy link
Member

The issue

The following code gives different results when executed on different runtime flavours:

  • coreCLR -> outputs: SomeOtherValue
  • Mono -> outputs: SomeValue
  • NativeAOT -> outputs: SomeValue
using System;
using System.Reflection;
using System.Runtime.CompilerServices;

public class Program
{
    internal abstract class UsableCustomConstantAttribute : CustomConstantAttribute
    {
        public sealed override object Value => RealValue;
        protected object RealValue { get; set; }
    }

    private class StringCustomConstantAttribute : UsableCustomConstantAttribute
    {
        public new object Value { get { return RealValue; } set { RealValue = value; } }
    }

    private class AnotherStringCustomConstantAttribute : UsableCustomConstantAttribute
    {
        public new object Value { get { return RealValue; } set { RealValue = value; } }
    }

    public void Foo([StringCustomConstant(Value = "SomeValue")] [AnotherStringCustomConstant(Value = "SomeOtherValue")] object param) { }

    static void Main()
    {
        Console.WriteLine(typeof(Program).GetMethod("Foo").GetParameters()[0].RawDefaultValue);
    }
}

Expected

All runtimes should produce the same result.

TODO

Align the implementation of RawDefaultValue resolution between runtimes.
Mono:


CoreCLR:
private object? GetDefaultValueInternal(bool raw)

NativeAOT:
public static bool GetCustomAttributeDefaultValueIfAny(IEnumerable<CustomAttributeData> customAttributes, bool raw, out object? defaultValue)


This is related to: #49806

@ivanpovazan ivanpovazan added this to the 8.0.0 milestone Sep 26, 2022
@ivanpovazan ivanpovazan self-assigned this Sep 26, 2022
@ghost
Copy link

ghost commented Sep 26, 2022

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

The issue

The following code gives different results when executed on different runtime flavours:

  • coreCLR -> outputs: SomeOtherValue
  • Mono -> outputs: SomeValue
  • NativeAOT -> outputs: SomeValue
using System;
using System.Reflection;
using System.Runtime.CompilerServices;

public class Program
{
    internal abstract class UsableCustomConstantAttribute : CustomConstantAttribute
    {
        public sealed override object Value => RealValue;
        protected object RealValue { get; set; }
    }

    private class StringCustomConstantAttribute : UsableCustomConstantAttribute
    {
        public new object Value { get { return RealValue; } set { RealValue = value; } }
    }

    private class AnotherStringCustomConstantAttribute : UsableCustomConstantAttribute
    {
        public new object Value { get { return RealValue; } set { RealValue = value; } }
    }

    public void Foo([StringCustomConstant(Value = "SomeValue")] [AnotherStringCustomConstant(Value = "SomeOtherValue")] object param) { }

    static void Main()
    {
        Console.WriteLine(typeof(Program).GetMethod("Foo").GetParameters()[0].RawDefaultValue);
    }
}

Expected

All runtimes should produce the same result.

TODO

Align the implementation of RawDefaultValue resolution between runtimes.
Mono:


CoreCLR:
private object? GetDefaultValueInternal(bool raw)

NativeAOT:
public static bool GetCustomAttributeDefaultValueIfAny(IEnumerable<CustomAttributeData> customAttributes, bool raw, out object? defaultValue)


This is related to: #49806

Author: ivanpovazan
Assignees: ivanpovazan
Labels:

area-System.Reflection, area-System.Reflection-mono, area-NativeAOT-coreclr

Milestone: 8.0.0

@ivanpovazan
Copy link
Member Author

cc @jkotas

@teo-tsirpanis
Copy link
Contributor

(we use only one area per issue)

@steveharter
Copy link
Member

Like CoreClr, .NET Framework also returns "SomeOtherValue" so assuming this is the expected result, Mono and NativeAOT should be changed to return the last parameter attribute.

If we agree that is the case, then this issue should be moved to [area-System.Reflection-mono] and another tracking issue logged for NativeAOT.

This does seem like a niche issue, however, since it requires multiple parameter attributes.

@jkotas
Copy link
Member

jkotas commented Sep 29, 2022

@steveharter Ivan is fixing this in #75612

ivanpovazan added a commit that referenced this issue Oct 3, 2022
@ivanpovazan
Copy link
Member Author

Closing as completed via 05b8bab

@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants