You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests.TestCustomAttributeDecoder is failed if tc is a native image file #23513
In fact, there are more failed tcs if they are ni files.
# in AnyOS.AnyCPU.$BuildMode/System.Runtime.Loader.RefEmitLoadContext.Tests /p:Outerloop=True
System.Runtime.Loader.Tests.RefEmitLoadContextTests.LoadRefEmitAssembly
# in AnyOS.AnyCPU.$BuildMode/System.Runtime.Tests /p:Outerloop=True
System.Reflection.Tests.AssemblyTests.AssemblyLoadFromBytes
System.Reflection.Tests.AssemblyTests.LoadFrom_SameIdentityAsAssemblyWithDifferentPath_ReturnsEqualAssemblies
# in Unix.AnyCPU.Release.$BuildMode/System.Runtime.Extensions.Tests /p:Outerloop=True
System.Tests.AppDomainTests.AssemblyLoad
System.Tests.AppDomainTests.Load
System.Tests.AppDomainTests.GetAssemblies
The above tcs use Reflection methods, so I think this issue may solve them. If the tcs are failed after this issue is solved, they should be submmited as new issues.
This tc TestCustomAttributeDecoder is testing whether decoding custom attributes of a class works correctly. To test it, CustomAttributeDecoderTests has multiple custom attributes. Remeber the order of the custom attributes.
namespaceSystem.Reflection.Metadata.Decoding.Tests{publicclassCustomAttributeDecoderTests{// ...// no arguments[Test]// multiple fixed arguments[Test("0",1,2.0)]// multiple named arguments[Test(StringField="0",Int32Field=1,SByteEnumArrayProperty=new[]{SByteEnum.Value})]// multiple fixed and named arguments[Test("0",1,2.0,StringField="0",Int32Field=1,DoubleField=2.0)]// single fixed null argument[Test((object)null)][Test((string)null)][Test((Type)null)][Test((int[])null)]// ...// null named arguments[Test(ObjectField=null)][Test(StringField=null)][Test(Int32ArrayProperty=null)]privatesealedclassHasAttributes{}
At runtime, CoreCLR has the custom attributes as metdata in somewhere. I don't know where the place is, but I can see them by below code. (source from here)
I found the difference between dll and ni.dll by above code.
.dll prints
Discovering: System.Reflection.Metadata.Tests
Discovered: System.Reflection.Metadata.Tests
Starting: System.Reflection.Metadata.Tests
FullName: System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+HasAttributes
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute()] # HERE
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute("0", (Int32)1, (Double)2)]
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute(StringField = "0", Int32Field = 1, SByteEnumArrayProperty = new System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+SByteEnu
m[1] { -1 })]
Named arguments
MemberInfo: System.String StringField
Type: 'System.String' Value: '0'
MemberInfo: Int32 Int32Field
Type: 'System.Int32' Value: '1'
MemberInfo: SByteEnum[] SByteEnumArrayProperty
Array of 'System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+SByteEnum[]':
Type: 'System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+SByteEnum' Value: '-1'
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute("0", (Int32)1, (Double)2, StringField = "0", Int32Field = 1, DoubleField = 2)]
Named arguments
MemberInfo: System.String StringField
Type: 'System.String' Value: '0'
MemberInfo: Int32 Int32Field
Type: 'System.Int32' Value: '1'
MemberInfo: Double DoubleField
Type: 'System.Double' Value: '2'
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((String)null)]
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((String)null)]
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((Type)null)]
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((Int32[])null)]
Named arguments
...
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute(ObjectField = (String)null)]
Named arguments
MemberInfo: System.Object ObjectField
CustomAttributeTypedArgument.Value: null
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute(StringField = null)]
Named arguments
MemberInfo: System.String StringField
CustomAttributeTypedArgument.Value: null
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute(Int32ArrayProperty = null)]
Named arguments
MemberInfo: Int32[] Int32ArrayProperty
CustomAttributeTypedArgument.Value: null
ni.dll prints
Discovering: System.Reflection.Metadata.Tests
Discovered: System.Reflection.Metadata.Tests
Starting: System.Reflection.Metadata.Tests
FullName: System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+HasAttributes
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+Int64Enum)-4)] # HERE
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute("0", (Int32)1, (Double)2)]
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute(StringField = "0", Int32Field = 1, SByteEnumArrayProperty = new System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+SByteEnu
m[1] { -1 })]
Named arguments
MemberInfo: System.String StringField
Type: 'System.String' Value: '0'
MemberInfo: Int32 Int32Field
Type: 'System.Int32' Value: '1'
MemberInfo: SByteEnum[] SByteEnumArrayProperty
Array of 'System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+SByteEnum[]':
Type: 'System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+SByteEnum' Value: '-1'
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute("0", (Int32)1, (Double)2, StringField = "0", Int32Field = 1, DoubleField = 2)]
Named arguments
MemberInfo: System.String StringField
Type: 'System.String' Value: '0'
MemberInfo: Int32 Int32Field
Type: 'System.Int32' Value: '1'
MemberInfo: Double DoubleField
Type: 'System.Double' Value: '2'
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((String)null)]
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((String)null)]
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((Type)null)]
Named arguments
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((Int32[])null)]
Named arguments
...
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute(ObjectField = (String)null)]
Named arguments
MemberInfo: System.Object ObjectField
CustomAttributeTypedArgument.Value: null
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute(StringField = null)]
Named arguments
MemberInfo: System.String StringField
CustomAttributeTypedArgument.Value: null
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute(Int32ArrayProperty = null)]
Named arguments
MemberInfo: Int32[] Int32ArrayProperty
CustomAttributeTypedArgument.Value: null
See the first custom attribute. dll prints [System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute()] right while ni.dll prints [System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+Int64Enum)-4)] wrong.
Need to investigate why the first custom attribute has wrong value when it is from ni.dll.
As above diff shows, the contents of CustomAttributes are same to each other. The difference is just order. However the tc System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests.TestCustomAttributeDecoder supposes that the first elem of reader.GetCustomAttributes(typeDefHandle) is [Test] which has no arguments. I don't know why this happens only in case of ni, anyway, this should be fixed.
It may be nice if tools always preserve order of custom attributes. A lot of tools do not do it today though, e.g. ildasm/ilasm roundtrip does not preserve the order of the custom attributes either.
Activity
YongseopKim commentedon Sep 11, 2017
/cc @dotnet/arm32-contrib @hqueue @parjong
YongseopKim commentedon Sep 12, 2017
This tc
TestCustomAttributeDecoderis testing whether decoding custom attributes of a class works correctly. To test it, CustomAttributeDecoderTests has multiple custom attributes. Remeber the order of the custom attributes.At runtime, CoreCLR has the custom attributes as metdata in somewhere. I don't know where the place is, but I can see them by below code. (source from here)
I found the difference between dll and ni.dll by above code.
See the first custom attribute. dll prints
[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute()]right while ni.dll prints[System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+TestAttribute((System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests+Int64Enum)-4)]wrong.Need to investigate why the first custom attribute has wrong value when it is from ni.dll.
YongseopKim commentedon Sep 12, 2017
Difference of ILDASM between dll and ni.dll
This result comes from
crossgen? orroslyn?YongseopKim commentedon Sep 13, 2017
I thinkcrossgenmade this results. I'll make a issue for this in coreclr.YongseopKim commentedon Sep 13, 2017
I found that the problem is not the first element of CustomAtrributes but the order of CustomAttributes. I got each order of CustomAttributes.
As above diff shows, the contents of CustomAttributes are same to each other. The difference is just order. However the tc
System.Reflection.Metadata.Decoding.Tests.CustomAttributeDecoderTests.TestCustomAttributeDecodersupposes that the first elem ofreader.GetCustomAttributes(typeDefHandle)is[Test]which has no arguments. I don't know why this happens only in case of ni, anyway, this should be fixed.YongseopKim commentedon Sep 13, 2017
https://github.com/dotnet/corefx/issues/6534 has related to this.
tmat commentedon Nov 16, 2017
@YongseopKim Sounds like a bug in NGEN to me. It should not reorder custom attributes.
tmat commentedon Nov 16, 2017
@sergiy-k Seems like NGEN/crossgen is changing the order of custom attributes in metadata, which it should not imo.
sergiy-k commentedon Nov 16, 2017
/cc: @nattress
jkotas commentedon Nov 16, 2017
It may be nice if tools always preserve order of custom attributes. A lot of tools do not do it today though, e.g. ildasm/ilasm roundtrip does not preserve the order of the custom attributes either.