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

Cannot set CustomAttribute to nested erasable type #365

Open
RahimovIR opened this issue Aug 17, 2021 · 0 comments
Open

Cannot set CustomAttribute to nested erasable type #365

RahimovIR opened this issue Aug 17, 2021 · 0 comments
Labels

Comments

@RahimovIR
Copy link

Description

Cannot set CustomAttribute to nested erasable type
CustomAttribute with Generative types work fine

Repro steps

Add nested type with custom attributes

    let createType typeName (count:int) =
        let myType = ProvidedTypeDefinition(asm, ns, typeName, Some typeof<obj>, isErased = true)
        let ctor = ProvidedConstructor([], invokeCode = fun args -> <@@ ():> obj @@>)
        myType.AddMember(ctor)

        let nestedType = ProvidedTypeDefinition("Nested", Some typeof<obj>)
        let attr = {
            new Reflection.CustomAttributeData() with
            member __.Constructor = (typeof<MyNamespace.MyAttribute>).GetConstructor([|typeof<string>|])
            member __.ConstructorArguments = [|"1"|] |> Array.map (fun i -> CustomAttributeTypedArgument(i.GetType(), i)) :> _
            member __.NamedArguments = [||] :> _
        }
        nestedType.AddCustomAttribute(attr)
        myType.AddMember nestedType

displaying a list of attributes in debug script

type B = LemonadeProvider.ErasingProvider<1>
let t2 = typeof<B.Nested>
t2.CustomAttributes |> Seq.iter(fun a -> printfn "%A" a )

Expected behavior

[MyNamespace.MyAttribute("1")]

Actual behavior

[System.SerializableAttribute()]
[System.Runtime.CompilerServices.TypeForwardedFromAttribute("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[System.Runtime.InteropServices.ComVisibleAttribute((Boolean)True)]
[System.Runtime.InteropServices.ClassInterfaceAttribute((System.Runtime.InteropServices.ClassInterfaceType)1)]
[System.Runtime.CompilerServices.NullableContextAttribute((Byte)2)]

Related information

  • Windows 10
  • master
  • CoreCLR
@dsyme dsyme added the bug label Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants