From dcb81934d0eec402d595381274de5d559f261fec Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Wed, 31 Jul 2024 17:56:54 -0700 Subject: [PATCH 1/4] Add AssemblyBuilder tests covering boundary / edge case scenarios --- .../Reflection/Emit/PropertyBuilderImpl.cs | 2 +- .../ModuleBuilder/ModuleBuilderDefineEnum.cs | 53 +++++- .../ModuleBuilder/ModuleBuilderDefineType.cs | 150 +++++++++++++++- .../AssemblySaveTools.cs | 7 + .../TypeBuilder/TypeBuilderDefineField.cs | 163 ++++++++++++++++-- .../TypeBuilder/TypeBuilderDefineMethod.cs | 94 +++++++++- .../TypeBuilder/TypeBuilderDefineProperty.cs | 81 ++++++++- .../System.Reflection.Emit/tests/Utilities.cs | 2 + 8 files changed, 517 insertions(+), 35 deletions(-) diff --git a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/PropertyBuilderImpl.cs b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/PropertyBuilderImpl.cs index 97de7d45d44911..d18289199a6273 100644 --- a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/PropertyBuilderImpl.cs +++ b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/PropertyBuilderImpl.cs @@ -33,7 +33,7 @@ internal PropertyBuilderImpl(string name, PropertyAttributes attributes, Calling _name = name; _attributes = attributes; _callingConvention = callingConvention; - _propertyType = returnType; + _propertyType = returnType ?? containingType.GetModuleBuilder().GetTypeFromCoreAssembly(CoreTypeId.Void); _parameterTypes = parameterTypes; _containingType = containingType; _returnTypeRequiredCustomModifiers = returnTypeRequiredCustomModifiers; diff --git a/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineEnum.cs b/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineEnum.cs index 67969cdee25436..0e9fb041ec4589 100644 --- a/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineEnum.cs +++ b/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineEnum.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; -using System.Runtime.InteropServices; +using System.IO; using Xunit; namespace System.Reflection.Emit.Tests @@ -18,13 +18,13 @@ public static IEnumerable DefineEnum_TestData() yield return new object[] { "a\0b\0c", TypeAttributes.Public, typeof(int) }; yield return new object[] { "Name", TypeAttributes.Public, typeof(uint) }; yield return new object[] { "Name", TypeAttributes.Public, typeof(long) }; - yield return new object[] { "Name", TypeAttributes.Public, typeof(char) }; - yield return new object[] { "Name", TypeAttributes.Public, typeof(bool) }; - yield return new object[] { "Name", TypeAttributes.Public, typeof(ulong) }; + yield return new object[] { "N%ame", TypeAttributes.Public, typeof(char) }; + yield return new object[] { "N`ame", TypeAttributes.Public, typeof(bool) }; + yield return new object[] { "N'ame", TypeAttributes.Public, typeof(ulong) }; yield return new object[] { "Name", TypeAttributes.Public, typeof(float) }; - yield return new object[] { "Name", TypeAttributes.Public, typeof(double) }; - yield return new object[] { "Name", TypeAttributes.Public, typeof(IntPtr) }; - yield return new object[] { "Name", TypeAttributes.Public, typeof(UIntPtr) }; + yield return new object[] { "Nam", TypeAttributes.Public, typeof(double) }; + yield return new object[] { "Nam~e", TypeAttributes.Public, typeof(IntPtr) }; + yield return new object[] { "\rName", TypeAttributes.Public, typeof(UIntPtr) }; yield return new object[] { "Name", TypeAttributes.Public, typeof(Int32Enum) }; } @@ -76,6 +76,45 @@ public void DefineEnum(string name, TypeAttributes visibility, Type underlyingTy Assert.Equal(FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName, createdUnderlyingField.Attributes); } + [Theory] + [MemberData(nameof(DefineEnum_TestData))] + public void DefineEnumPersistedAssembly(string name, TypeAttributes visibility, Type underlyingType) + { + PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilder(new AssemblyName("MyAssembly")); + ModuleBuilder module = ab.DefineDynamicModule("MyModule"); + EnumBuilder enumBuilder = module.DefineEnum(name, visibility, underlyingType); + enumBuilder.CreateType(); + + Assert.True(enumBuilder.IsEnum); + Assert.Equal(module.Assembly, enumBuilder.Assembly); + Assert.Equal(module, enumBuilder.Module); + Assert.Equal(name, enumBuilder.Name); + Assert.Equal(Helpers.GetFullName(name), enumBuilder.FullName); + Assert.Equal(typeof(Enum), enumBuilder.BaseType); + Assert.Null(enumBuilder.DeclaringType); + Assert.Equal(visibility | TypeAttributes.Sealed, enumBuilder.Attributes); + Assert.Equal("value__", enumBuilder.UnderlyingField.Name); + Assert.Equal(underlyingType, enumBuilder.UnderlyingField.FieldType); + Assert.Equal(FieldAttributes.Public | FieldAttributes.SpecialName, enumBuilder.UnderlyingField.Attributes); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + Assembly assemblyFromStream = mlc.LoadFromStream(stream); + Type createdEnum = assemblyFromStream.GetType(name); + if (createdEnum != null) // null when name = "a\0b\0c" + { + Assert.True(createdEnum.IsEnum); + Assert.Equal(Helpers.GetFullName(name), createdEnum.Name); + Assert.Equal(Helpers.GetFullName(name), enumBuilder.FullName); + Assert.Equal(typeof(Enum).FullName, createdEnum.BaseType.FullName); + Assert.Null(createdEnum.DeclaringType); + Assert.Equal(visibility | TypeAttributes.Sealed, createdEnum.Attributes); + } + } + } + [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/2389", TestRuntimes.Mono)] public void DefineEnum_DynamicUnderlyingType_Works() diff --git a/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineType.cs b/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineType.cs index c2dd2d16bfba8d..fb253350e523af 100644 --- a/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineType.cs +++ b/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineType.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Xunit; using System.Diagnostics.CodeAnalysis; +using System.IO; namespace System.Reflection.Emit.Tests { @@ -12,7 +13,7 @@ public class ModuleBuilderDefineType { public static IEnumerable TestData() { - foreach (string name in new string[] { "TestName", "testname", "class", "\uD800\uDC00" }) + foreach (string name in new string[] { "TestName", "testname", "class", "\uD800\uDC00", "432" }) { foreach (TypeAttributes attributes in new TypeAttributes[] { TypeAttributes.NotPublic, TypeAttributes.Interface | TypeAttributes.Abstract, TypeAttributes.Class }) { @@ -94,6 +95,153 @@ void Verify(TypeBuilder type, Module module) } } + [Theory] + [MemberData(nameof(TestData))] + public void DefineTypePersistedAssembly(string name, TypeAttributes attributes, Type parent, PackingSize packingSize, int typesize, Type[] implementedInterfaces) + { + bool isDefaultImplementedInterfaces = implementedInterfaces?.Length == 0; + bool isDefaultPackingSize = packingSize == PackingSize.Unspecified; + bool isDefaultSize = typesize == 0; + bool isDefaultParent = parent == null; + bool isDefaultAttributes = attributes == TypeAttributes.NotPublic; + Type baseType = attributes.HasFlag(TypeAttributes.Abstract) && parent == null ? null : (parent ?? typeof(object)); + + void VerifyTypeBuilder(TypeBuilder type, Module module) + { + Assert.Equal(module, type.Module); + Assert.Equal(module.Assembly, type.Assembly); + Assert.Equal(name, type.Name); + Assert.Equal(Helpers.GetFullName(name), type.FullName); + Assert.Equal(attributes, type.Attributes); + Assert.Equal(baseType, type.BaseType); + Assert.Equal(typesize, type.Size); + Assert.Equal(packingSize, type.PackingSize); + Assert.Equal(implementedInterfaces ?? new Type[0], type.GetInterfaces()); + } + + void VerifyType(Type createdType) + { + Assert.Equal(name, createdType.Name); + Assert.Equal(attributes, createdType.Attributes); + Assert.Equal(Helpers.GetFullName(name), createdType.FullName); + Assert.Equal(attributes, createdType.Attributes); + if (baseType != null) + { + Assert.Equal(baseType.Name, createdType.BaseType.Name); + } + Assert.Equal((implementedInterfaces ?? new Type[0]).Length, createdType.GetInterfaces().Length); + } + + PersistedAssemblyBuilder ab; + TypeBuilder typeBuilder; + if (isDefaultImplementedInterfaces) + { + if (isDefaultSize && isDefaultPackingSize) + { + if (isDefaultParent) + { + if (isDefaultAttributes) + { + // Use DefineType(string) + ab = AssemblySaveTools.PopulateAssemblyAndModule(out ModuleBuilder module1); + typeBuilder = module1.DefineType(name); + typeBuilder.CreateType(); + VerifyTypeBuilder(typeBuilder, module1); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + VerifyType(mlc.LoadFromStream(stream).GetType(name)); + } + } + // Use DefineType(string, TypeAttributes) + ab = AssemblySaveTools.PopulateAssemblyAndModule(out ModuleBuilder module2); + typeBuilder = module2.DefineType(name, attributes); + typeBuilder.CreateType(); + VerifyTypeBuilder(typeBuilder, module2); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + VerifyType(mlc.LoadFromStream(stream).GetType(name)); + } + } + // Use DefineType(string, TypeAttributes, Type) + ab = AssemblySaveTools.PopulateAssemblyAndModule(out ModuleBuilder module3); + typeBuilder = module3.DefineType(name, attributes, parent); + typeBuilder.CreateType(); + VerifyTypeBuilder(typeBuilder, module3); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + VerifyType(mlc.LoadFromStream(stream).GetType(name)); + } + } + else if (isDefaultSize) + { + // Use DefineType(string, TypeAttributes, Type, PackingSize) + ab = AssemblySaveTools.PopulateAssemblyAndModule(out ModuleBuilder module4); + typeBuilder = module4.DefineType(name, attributes, parent, packingSize); + typeBuilder.CreateType(); + VerifyTypeBuilder(typeBuilder, module4); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + VerifyType(mlc.LoadFromStream(stream).GetType(name)); + } + } + else if (isDefaultPackingSize) + { + // Use DefineType(string, TypeAttributes, Type, int) + ab = AssemblySaveTools.PopulateAssemblyAndModule(out ModuleBuilder module5); + typeBuilder = module5.DefineType(name, attributes, parent, typesize); + typeBuilder.CreateType(); + VerifyTypeBuilder(typeBuilder, module5); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + VerifyType(mlc.LoadFromStream(stream).GetType(name)); + } + } + // Use DefineType(string, TypeAttributes, Type, PackingSize, int) + ab = AssemblySaveTools.PopulateAssemblyAndModule(out ModuleBuilder module6); + typeBuilder = module6.DefineType(name, attributes, parent, packingSize, typesize); + typeBuilder.CreateType(); + VerifyTypeBuilder(typeBuilder, module6); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + VerifyType(mlc.LoadFromStream(stream).GetType(name)); + } + } + else + { + // Use DefineType(string, TypeAttributes, Type, Type[]) + Assert.True(isDefaultSize && isDefaultPackingSize); // Sanity check + ab = AssemblySaveTools.PopulateAssemblyAndModule(out ModuleBuilder module7); + typeBuilder = module7.DefineType(name, attributes, parent, implementedInterfaces); + typeBuilder.CreateType(); + VerifyTypeBuilder(typeBuilder, module7); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + VerifyType(mlc.LoadFromStream(stream).GetType(name)); + } + } + } + [Fact] public void DefineType_String_TypeAttributes_Type_TypeCreatedInModule() { diff --git a/src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTools.cs b/src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTools.cs index 6c2d65fb7ad406..f3e60196ea44f1 100644 --- a/src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTools.cs +++ b/src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTools.cs @@ -82,6 +82,13 @@ internal static PersistedAssemblyBuilder PopulateAssemblyBuilderAndTypeBuilder(o return ab; } + internal static PersistedAssemblyBuilder PopulateAssemblyAndModule(out ModuleBuilder moduleBuilder) + { + PersistedAssemblyBuilder ab = PopulateAssemblyBuilder(s_assemblyName, null); + moduleBuilder = ab.DefineDynamicModule("MyModule"); + return ab; + } + internal static PersistedAssemblyBuilder PopulateAssemblyBuilder(AssemblyName assemblyName, List? assemblyAttributes = null) => new PersistedAssemblyBuilder(assemblyName, CoreMetadataAssemblyResolver.s_coreAssembly, assemblyAttributes); diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs index c81709bc0ef0bb..6d25be45200ded 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs @@ -2,8 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.IO; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using Xunit; namespace System.Reflection.Emit.Tests @@ -18,18 +18,18 @@ public static IEnumerable TestData() yield return new object[] { "\uD800\uDC00", Helpers.DynamicType(TypeAttributes.Public).AsType(), FieldAttributes.Family, FieldAttributes.Family }; yield return new object[] { "\u043F\u0440\u0438\u0432\u0435\u0442", typeof(EmptyNonGenericInterface1), FieldAttributes.FamORAssem, FieldAttributes.FamORAssem }; yield return new object[] { "Test Name With Spaces", typeof(EmptyEnum), FieldAttributes.Public, FieldAttributes.Public }; - yield return new object[] { "TestName", typeof(EmptyNonGenericClass), FieldAttributes.HasDefault, FieldAttributes.PrivateScope }; - yield return new object[] { "TestName", typeof(EmptyNonGenericStruct), FieldAttributes.HasFieldMarshal, FieldAttributes.PrivateScope }; - yield return new object[] { "TestName", typeof(EmptyGenericClass), FieldAttributes.HasFieldRVA, FieldAttributes.PrivateScope }; - yield return new object[] { "TestName", typeof(EmptyGenericStruct), FieldAttributes.Literal, FieldAttributes.Literal }; - yield return new object[] { "TestName", typeof(int), FieldAttributes.NotSerialized, FieldAttributes.NotSerialized }; - yield return new object[] { "TestName", typeof(int[]), FieldAttributes.PinvokeImpl, FieldAttributes.PinvokeImpl }; - yield return new object[] { "TestName", typeof(int).MakePointerType(), FieldAttributes.Private, FieldAttributes.Private }; - yield return new object[] { "TestName", typeof(EmptyGenericClass<>), FieldAttributes.PrivateScope, FieldAttributes.PrivateScope }; - yield return new object[] { "TestName", typeof(int), FieldAttributes.Public, FieldAttributes.Public }; - yield return new object[] { "TestName", typeof(int), FieldAttributes.RTSpecialName, FieldAttributes.PrivateScope }; - yield return new object[] { "TestName", typeof(int), FieldAttributes.SpecialName, FieldAttributes.SpecialName }; - yield return new object[] { "TestName", typeof(int), FieldAttributes.Public | FieldAttributes.Static, FieldAttributes.Public | FieldAttributes.Static }; + yield return new object[] { "Test(N)ame", typeof(EmptyNonGenericClass), FieldAttributes.HasDefault, FieldAttributes.PrivateScope }; + yield return new object[] { "Test.Name", typeof(EmptyNonGenericStruct), FieldAttributes.HasFieldMarshal, FieldAttributes.PrivateScope }; + yield return new object[] { "Test/Name", typeof(EmptyGenericClass), FieldAttributes.HasFieldRVA, FieldAttributes.PrivateScope }; + yield return new object[] { "Test-Name", typeof(EmptyGenericStruct), FieldAttributes.Literal, FieldAttributes.Literal }; + yield return new object[] { "Test&Name", typeof(int), FieldAttributes.NotSerialized, FieldAttributes.NotSerialized }; + yield return new object[] { "Test^Name", typeof(int[]), FieldAttributes.PinvokeImpl, FieldAttributes.PinvokeImpl }; + yield return new object[] { "Test%Name", typeof(int).MakePointerType(), FieldAttributes.Private, FieldAttributes.Private }; + yield return new object[] { "Test$Name", typeof(EmptyGenericClass<>), FieldAttributes.PrivateScope, FieldAttributes.PrivateScope }; + yield return new object[] { "Test\"Name", typeof(int), FieldAttributes.Public, FieldAttributes.Public }; + yield return new object[] { "1Test'Name", typeof(int), FieldAttributes.RTSpecialName, FieldAttributes.PrivateScope }; + yield return new object[] { "#Test`Name", typeof(int), FieldAttributes.SpecialName, FieldAttributes.SpecialName }; + yield return new object[] { "42", typeof(int), FieldAttributes.Public | FieldAttributes.Static, FieldAttributes.Public | FieldAttributes.Static }; } [Theory] @@ -60,6 +60,143 @@ public void DefineField(string name, Type fieldType, FieldAttributes attributes, } } + [Theory] + [MemberData(nameof(TestData))] + public void DefineFieldPersistedAssembly(string name, Type fieldType, FieldAttributes attributes, FieldAttributes expectedAttributes) + { + PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); + FieldBuilder field = type.DefineField(name, fieldType, attributes); + Assert.Equal(name, field.Name); + Assert.Equal(fieldType, field.FieldType); + Assert.Equal(expectedAttributes, field.Attributes); + Assert.Equal(type.AsType(), field.DeclaringType); + Assert.Equal(field.Module, field.Module); + + Type createdType = type.CreateType(); + Assert.Equal(type.AsType().GetFields(Helpers.AllFlags), createdType.GetFields(Helpers.AllFlags)); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + createdType = mlc.LoadFromStream(stream).GetType("MyType"); + FieldInfo fieldInfo = createdType.GetField(name, Helpers.AllFlags); + if (fieldInfo != null) + { + Assert.Equal(name, fieldInfo.Name); + Assert.Equal(expectedAttributes, field.Attributes); + } + } + } + + [Fact] + public void DefineField_NameCollision() + { + TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public); + FieldBuilder field1 = type.DefineField("FieldName", typeof(int), FieldAttributes.Public); + FieldBuilder field2 = type.DefineField("FieldName", typeof(int), FieldAttributes.Public); + FieldBuilder field3 = type.DefineField("FieldName", typeof(string), FieldAttributes.Public); + FieldBuilder field4 = type.DefineField("FieldName", typeof(string), FieldAttributes.Public); + Type createdType = type.CreateType(); + + FieldInfo[] fields = createdType.GetFields(Helpers.AllFlags); + Assert.Equal(4, fields.Length); + Assert.Equal("FieldName", fields[0].Name); + Assert.Equal("FieldName", fields[1].Name); + Assert.Equal("FieldName", fields[2].Name); + Assert.Equal("FieldName", fields[3].Name); + Assert.Throws(() => createdType.GetField("FieldName", Helpers.AllFlags)); + } + + [Fact] + public void DefineField_NameCollisionPersistedAssembly() + { + PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); + FieldBuilder field1 = type.DefineField("FieldName", typeof(int), FieldAttributes.Public); + FieldBuilder field2 = type.DefineField("FieldName", typeof(int), FieldAttributes.Public); + FieldBuilder field3 = type.DefineField("FieldName", typeof(string), FieldAttributes.Public); + type.CreateType(); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + Type createdType = mlc.LoadFromStream(stream).GetType("MyType"); + FieldInfo[] fields = createdType.GetFields(Helpers.AllFlags); + Assert.Equal(3, fields.Length); + Assert.Equal("FieldName", fields[0].Name); + Assert.Equal("FieldName", fields[1].Name); + Assert.Throws(() => createdType.GetField("FieldName", Helpers.AllFlags)); + } + } + + [Fact] + public void DefineField_65536Fields() + { + TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public); + for (int i = 0; i < 65536; i++) + { + type.DefineField($"F_{i}", typeof(int), FieldAttributes.Public); + } + + // System.TypeLoadException : Internal limitation: too many fields. + Assert.Throws(() => type.CreateType()); + } + + [Fact] + public void DefineField_65536FieldsPersistedAssembly() + { + PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); + for (int i = 0; i < 65536; i++) + { + type.DefineField($"F_{i}", typeof(int), FieldAttributes.Public); + } + type.CreateType(); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + Type createdType = mlc.LoadFromStream(stream).GetType("MyType"); + FieldInfo[] fields = createdType.GetFields(Helpers.AllFlags); + Assert.Equal(65536, fields.Length); + Assert.Equal("F_65535", fields[65535].Name); + } + } + + [Fact] + public void DefineFieldMethod_LongName() + { + TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public); + type.DefineField(Helpers.s_512Chars, typeof(int), FieldAttributes.Public); + type.DefineMethod(Helpers.s_512Chars, MethodAttributes.Public, typeof(void), Type.EmptyTypes).GetILGenerator().Emit(OpCodes.Ret); + + Type createdType = type.CreateType(); + FieldInfo field = createdType.GetField(Helpers.s_512Chars); + Assert.Equal(Helpers.s_512Chars, field.Name); + MethodInfo method = createdType.GetMethod(Helpers.s_512Chars); + Assert.Equal(Helpers.s_512Chars, method.Name); + } + + [Fact] + public void DefineFieldMethod_LongNamePersistedAssembly() + { + PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); + type.DefineField(Helpers.s_512Chars, typeof(int), FieldAttributes.Public); + type.DefineMethod(Helpers.s_512Chars, MethodAttributes.Public, typeof(void), Type.EmptyTypes).GetILGenerator().Emit(OpCodes.Ret); + type.CreateType(); + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + Type createdType = mlc.LoadFromStream(stream).GetType("MyType"); + FieldInfo field = createdType.GetField(Helpers.s_512Chars); + Assert.Equal(Helpers.s_512Chars, field.Name); + MethodInfo method = createdType.GetMethod(Helpers.s_512Chars); + Assert.Equal(Helpers.s_512Chars, method.Name); + } + } + [Fact] public void DefineField_CalledTwice_Works() { diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs index 9d32a4dacee0c9..0873068278d87d 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.IO; +using System.Runtime.Loader; using Xunit; namespace System.Reflection.Emit.Tests @@ -34,10 +36,10 @@ public static IEnumerable TestData() yield return new object[] { "Name", MethodAttributes.Virtual, CallingConventions.Standard, null, null }; yield return new object[] { "Name", MethodAttributes.VtableLayoutMask, CallingConventions.Standard, null, null }; yield return new object[] { "Name", MethodAttributes.Abstract | MethodAttributes.Public | MethodAttributes.NewSlot | MethodAttributes.Virtual, CallingConventions.Standard, null, null }; - yield return new object[] { "Name", MethodAttributes.Final | MethodAttributes.Private | MethodAttributes.SpecialName | MethodAttributes.Static, CallingConventions.Standard, null, null }; + yield return new object[] { "A!?123C\"", MethodAttributes.Final | MethodAttributes.Private | MethodAttributes.SpecialName | MethodAttributes.Static, CallingConventions.Standard, null, null }; // Static - yield return new object[] { "Name", MethodAttributes.Static, CallingConventions.Any, null, null }; + yield return new object[] { "`Name", MethodAttributes.Static, CallingConventions.Any, null, null }; yield return new object[] { "Name", MethodAttributes.Static, CallingConventions.ExplicitThis, null, null }; yield return new object[] { "Name", MethodAttributes.Static, CallingConventions.HasThis, null, null }; yield return new object[] { "Name", MethodAttributes.Static, CallingConventions.Standard, null, null }; @@ -46,19 +48,19 @@ public static IEnumerable TestData() yield return new object[] { "Name", MethodAttributes.Static, CallingConventions.Any | CallingConventions.VarArgs, null, null }; yield return new object[] { "Name", MethodAttributes.Static, CallingConventions.HasThis | CallingConventions.Standard, null, null }; yield return new object[] { "Name", MethodAttributes.Static, CallingConventions.HasThis | CallingConventions.ExplicitThis, null, null }; - yield return new object[] { "Name", MethodAttributes.Static, (CallingConventions)(-1), null, null }; + yield return new object[] { "\uD800\uDC00", MethodAttributes.Static, (CallingConventions)(-1), null, null }; // Instance yield return new object[] { "Name", MethodAttributes.Public, CallingConventions.Any, null, null }; yield return new object[] { "Name", MethodAttributes.Public, CallingConventions.ExplicitThis, null, null }; - yield return new object[] { "Name", MethodAttributes.Public, CallingConventions.HasThis, null, null }; + yield return new object[] { "Na.me", MethodAttributes.Public, CallingConventions.HasThis, null, null }; yield return new object[] { "Name", MethodAttributes.Public, CallingConventions.Standard, null, null }; - yield return new object[] { "Name", MethodAttributes.Public, CallingConventions.VarArgs, null, null }; - yield return new object[] { "Name", MethodAttributes.Public, CallingConventions.Any | CallingConventions.Standard, null, null }; + yield return new object[] { "Na{m}e", MethodAttributes.Public, CallingConventions.VarArgs, null, null }; + yield return new object[] { "Na*me", MethodAttributes.Public, CallingConventions.Any | CallingConventions.Standard, null, null }; yield return new object[] { "Name", MethodAttributes.Public, CallingConventions.Any | CallingConventions.VarArgs, null, null }; - yield return new object[] { "Name", MethodAttributes.Public, CallingConventions.HasThis | CallingConventions.Standard, null, null }; + yield return new object[] { "Name$", MethodAttributes.Public, CallingConventions.HasThis | CallingConventions.Standard, null, null }; yield return new object[] { "Name", MethodAttributes.Public, CallingConventions.HasThis | CallingConventions.ExplicitThis, null, null }; - yield return new object[] { "Name", MethodAttributes.Public, (CallingConventions)(-1), null, null }; + yield return new object[] { "42", MethodAttributes.Public, (CallingConventions)(-1), null, null }; } [Theory] @@ -94,6 +96,82 @@ public void DefineMethod(string name, MethodAttributes attributes, CallingConven VerifyMethod(type4, method4, name, attributes, callingConvention, returnType, parameterTypes); } + [Theory] + [MemberData(nameof(TestData))] + public void DefineMethodPersistedAssembly(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) + { + AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); + bool defaultReturnTypeAndParameters = returnType == null && parameterTypes == null; + if (callingConvention == CallingConventions.Standard) + { + if (defaultReturnTypeAndParameters) + { + // Use DefineMethod(string, MethodAttributes) + MethodBuilder method1 = type.DefineMethod(name, attributes); + VerifyMethod(type, method1, name, attributes, callingConvention, returnType, parameterTypes); + } + // Use DefineMethod(string, MethodAttributes, Type, Type[]) + MethodBuilder method2 = type.DefineMethod(name, attributes, returnType, parameterTypes); + VerifyMethod(type, method2, name, attributes, callingConvention, returnType, parameterTypes); + } + if (defaultReturnTypeAndParameters) + { + // Use DefineMethod(string, MethodAttributes, CallingConventions) + MethodBuilder method3 = type.DefineMethod(name, attributes, callingConvention); + VerifyMethod(type, method3, name, attributes, callingConvention, returnType, parameterTypes); + } + // Use DefineMethod(string, MethodAttributes, CallingConventions, Type, Type[]) + MethodBuilder method4 = type.DefineMethod(name, attributes, callingConvention, returnType, parameterTypes); + VerifyMethod(type, method4, name, attributes, callingConvention, returnType, parameterTypes); + } + + [Fact] + public void DefineMethod_65536Methods() + { + TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public); + for (int i = 0; i < 65536; i++) + { + type.DefineMethod($"M_{i}", MethodAttributes.Public).GetILGenerator().Emit(OpCodes.Ret); + } + + // System.TypeLoadException : Type 'TestType' from assembly 'TestAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' + // contains more methods than the current implementation allows. + Assert.Throws(() => type.CreateType()); + } + + [Fact] + public void DefineMethod_65536MethodsPersistedAssembly() + { + PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilder(new AssemblyName("DefineMethod_65536MethodsPersistedAssembly")); + TypeBuilder type = ab.DefineDynamicModule("MyModule").DefineType("MyType", TypeAttributes.Public); + for (int i = 0; i < 65536; i++) + { + MethodBuilder method = type.DefineMethod($"M_{i}", MethodAttributes.Public | MethodAttributes.Static, typeof(int), Type.EmptyTypes); + ILGenerator il = method.GetILGenerator(); + il.Emit(OpCodes.Ldc_I4, i); + il.Emit(OpCodes.Ret); + } + type.CreateType(); + + using (var stream = new MemoryStream()) + { + ab.Save(stream); + stream.Seek(0, SeekOrigin.Begin); + var assembly = AssemblyLoadContext.Default.LoadFromStream(stream); + // System.TypeLoadException : Type 'MyType' from assembly 'MyDynamicAssembly, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null' + // contains more methods than the current implementation allows. + Assert.Throws(() => assembly.GetType("MyType")); + + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + Type createdType = mlc.LoadFromStream(stream).GetType("MyType"); // Loads with MLC + MethodInfo[] methods = createdType.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); + Assert.Equal(65536, methods.Length); + Assert.Equal("M_65535", methods[65535].Name); + } + } + } + [Fact] public void DefineMethod_MultipleOverloads_Works() { diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs index 84d27ee2f98e31..1fc18a1b099a1a 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.IO; using Xunit; namespace System.Reflection.Emit.Tests @@ -16,11 +17,12 @@ public static IEnumerable TestData() yield return new object[] { "\u043F\u0440\u0438\u0432\u0435\u0442", PropertyAttributes.SpecialName, typeof(EmptyNonGenericStruct), null, "\u043F\u0440\u0438\u0432\u0435\u0442", PropertyAttributes.SpecialName }; yield return new object[] { "class", (PropertyAttributes)(-1), null, new Type[] { typeof(void) }, "class", PropertyAttributes.None }; yield return new object[] { "Test Name With Spaces", (PropertyAttributes)8192, typeof(string), new Type[] { typeof(string) }, "Test Name With Spaces", PropertyAttributes.None }; - yield return new object[] { "PropertyName", PropertyAttributes.None, typeof(BasicDelegate), new Type[] { typeof(int) }, "PropertyName", PropertyAttributes.None }; - yield return new object[] { "PropertyName", PropertyAttributes.None, typeof(EmptyEnum), new Type[] { typeof(int) }, "PropertyName", PropertyAttributes.None }; - yield return new object[] { "PropertyName", PropertyAttributes.None, typeof(DateTime), new Type[] { typeof(int) }, "PropertyName", PropertyAttributes.None }; - yield return new object[] { "PropertyName", PropertyAttributes.None, typeof(EmptyGenericStruct), new Type[] { typeof(int) }, "PropertyName", PropertyAttributes.None }; - yield return new object[] { "PropertyName", PropertyAttributes.None, typeof(EmptyGenericStruct).GetGenericArguments()[0], new Type[] { typeof(int) }, "PropertyName", PropertyAttributes.None }; + yield return new object[] { "Property,Name", PropertyAttributes.None, typeof(BasicDelegate), new Type[] { typeof(int) }, "Property,Name", PropertyAttributes.None }; + yield return new object[] { "Property.Name", PropertyAttributes.None, typeof(EmptyEnum), new Type[] { typeof(int) }, "Property.Name", PropertyAttributes.None }; + yield return new object[] { "Property\nName", PropertyAttributes.None, typeof(DateTime), new Type[] { typeof(int) }, "Property\nName", PropertyAttributes.None }; + yield return new object[] { "Property@Name", PropertyAttributes.None, typeof(EmptyGenericStruct), new Type[] { typeof(int) }, "Property@Name", PropertyAttributes.None }; + yield return new object[] { "Property*Name", PropertyAttributes.None, typeof(EmptyGenericStruct).GetGenericArguments()[0], new Type[] { typeof(int) }, "Property*Name", PropertyAttributes.None }; + yield return new object[] { "0x42", PropertyAttributes.None, typeof(int), new Type[] { typeof(int) }, "0x42", PropertyAttributes.None }; // Invalid unicode yield return new object[] { "\uDC00", (PropertyAttributes)0x8000, typeof(EmptyGenericStruct), new Type[] { typeof(EmptyGenericClass) }, "\uFFFD", PropertyAttributes.None }; @@ -48,6 +50,75 @@ public void DefineProperty(string name, PropertyAttributes attributes, Type retu Assert.Equal(returnType ?? typeof(void), createdProperty.PropertyType); } + [Theory] + [MemberData(nameof(TestData))] + public void DefinePropertyPersistedAssembly(string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes, string expectedName, PropertyAttributes _) + { + PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); + PropertyBuilder property = type.DefineProperty(name, attributes, returnType, parameterTypes); + Assert.Equal(name, property.Name); + Assert.Equal(attributes, property.Attributes); + Assert.Equal(returnType ?? typeof(void), property.PropertyType); + + type.CreateType(); + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + + Assembly assemblyFromStream = mlc.LoadFromStream(stream); + Type createdType = assemblyFromStream.GetType("MyType"); + + PropertyInfo createdProperty = createdType.GetProperty(expectedName, Helpers.AllFlags); + Assert.Equal(expectedName, createdProperty.Name); + Type retType = returnType ?? typeof(void); + Assert.Equal(retType.FullName, createdProperty.PropertyType.FullName); + } + } + + [Fact] + public void DefineProperty_NameCollision() + { + TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public); + Type[] parameterTypes = { typeof(int), typeof(double) }; + PropertyBuilder property1 = type.DefineProperty("PropertyName", PropertyAttributes.None, typeof(int), parameterTypes); + PropertyBuilder property2 = type.DefineProperty("PropertyName", PropertyAttributes.None, typeof(int), parameterTypes); + PropertyBuilder property3 = type.DefineProperty("PropertyName", PropertyAttributes.None, typeof(string), [typeof(int)]); + Type createdType = type.CreateType(); + + PropertyInfo[] properties = createdType.GetProperties(Helpers.AllFlags); + Assert.Equal(2, properties.Length); + Assert.Equal("PropertyName", properties[0].Name); + Assert.Equal("PropertyName", properties[1].Name); + Assert.Throws(() => createdType.GetProperty("PropertyName", Helpers.AllFlags)); + } + + [Fact] + public void DefineProperty_NameCollisionPersistedAssembly() + { + PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); + Type[] parameterTypes = { typeof(int), typeof(double) }; + PropertyBuilder property1 = type.DefineProperty("PropertyName", PropertyAttributes.None, typeof(int), parameterTypes); + PropertyBuilder property2 = type.DefineProperty("PropertyName", PropertyAttributes.None, typeof(int), parameterTypes); + PropertyBuilder property3 = type.DefineProperty("PropertyName", PropertyAttributes.None, typeof(string), [typeof(int)]); + type.CreateType(); + + using (var stream = new MemoryStream()) + using (MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver())) + { + ab.Save(stream); + + Assembly assemblyFromStream = mlc.LoadFromStream(stream); + Type createdType = assemblyFromStream.GetType("MyType"); + + PropertyInfo[] properties = createdType.GetProperties(Helpers.AllFlags); + Assert.Equal(3, properties.Length); + Assert.Equal("PropertyName", properties[0].Name); + Assert.Equal("PropertyName", properties[1].Name); + Assert.Throws(() => createdType.GetProperty("PropertyName", Helpers.AllFlags)); + } + } + [Fact] public void DefineProperty_NullCustomModifiers() { diff --git a/src/libraries/System.Reflection.Emit/tests/Utilities.cs b/src/libraries/System.Reflection.Emit/tests/Utilities.cs index 4c01aba08f8c79..4baf34722a49d9 100644 --- a/src/libraries/System.Reflection.Emit/tests/Utilities.cs +++ b/src/libraries/System.Reflection.Emit/tests/Utilities.cs @@ -41,6 +41,8 @@ public static Type AsType(this Type type) public static class Helpers { + public const string s_512Chars = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + public const BindingFlags AllFlags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; public static AssemblyBuilder DynamicAssembly(string name = "TestAssembly", AssemblyBuilderAccess access = AssemblyBuilderAccess.Run) From 55a9650fccce162cbca78b287cc4ed4ce288d54d Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Thu, 1 Aug 2024 13:57:20 -0700 Subject: [PATCH 2/4] Make returnType parameter nullable, add test conditions for browser --- .../System/Reflection/Emit/RuntimePropertyBuilder.cs | 4 ++-- .../src/System/Reflection/Emit/RuntimeTypeBuilder.cs | 2 +- .../src/System/Reflection/Emit/TypeBuilder.cs | 10 +++++----- .../ref/System.Reflection.Emit.cs | 10 +++++----- .../src/System/Reflection/Emit/PropertyBuilderImpl.cs | 2 +- .../src/System/Reflection/Emit/TypeBuilderImpl.cs | 2 +- .../tests/ModuleBuilder/ModuleBuilderDefineEnum.cs | 2 +- .../tests/ModuleBuilder/ModuleBuilderDefineType.cs | 2 +- .../tests/TypeBuilder/TypeBuilderDefineField.cs | 8 ++++---- .../tests/TypeBuilder/TypeBuilderDefineMethod.cs | 4 ++-- .../tests/TypeBuilder/TypeBuilderDefineProperty.cs | 6 +++--- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimePropertyBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimePropertyBuilder.cs index eccafa7da3f2f6..9c6bad8f0bb00a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimePropertyBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimePropertyBuilder.cs @@ -29,7 +29,7 @@ internal RuntimePropertyBuilder( RuntimeModuleBuilder mod, // the module containing this PropertyBuilder string name, // property name PropertyAttributes attr, // property attribute such as DefaultProperty, Bindable, DisplayBind, etc - Type returnType, // return type of the property. + Type? returnType, // return type of the property. int prToken, // the metadata token for this property RuntimeTypeBuilder containingType) // the containing type { @@ -40,7 +40,7 @@ internal RuntimePropertyBuilder( m_name = name; m_moduleBuilder = mod; m_attributes = attr; - m_returnType = returnType; + m_returnType = returnType ?? typeof(void); m_tkProperty = prToken; m_containingType = containingType; } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs index 19720ba96b5e04..6be37fbf048f64 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs @@ -1388,7 +1388,7 @@ protected override FieldBuilder DefineUninitializedDataCore(string name, int siz #region Define Properties and Events protected override PropertyBuilder DefinePropertyCore(string name, PropertyAttributes attributes, CallingConventions callingConvention, - Type returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, + Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers) { lock (SyncRoot) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs index 1ae9e44c88cac1..aaf64eeb3ceebe 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs @@ -225,22 +225,22 @@ protected abstract MethodBuilder DefinePInvokeMethodCore(string name, string dll Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers, CallingConvention nativeCallConv, CharSet nativeCharSet); - public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[]? parameterTypes) + public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type? returnType, Type[]? parameterTypes) => DefineProperty(name, attributes, returnType, null, null, parameterTypes, null, null); public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, - CallingConventions callingConvention, Type returnType, Type[]? parameterTypes) + CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes) => DefineProperty(name, attributes, callingConvention, returnType, null, null, parameterTypes, null, null); public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, - Type returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, + Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers) => DefineProperty(name, attributes, default, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers); public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, - Type returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, + Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers) { ArgumentException.ThrowIfNullOrEmpty(name); @@ -251,7 +251,7 @@ public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes } protected abstract PropertyBuilder DefinePropertyCore(string name, PropertyAttributes attributes, CallingConventions callingConvention, - Type returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, + Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers); public ConstructorBuilder DefineTypeInitializer() diff --git a/src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs b/src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs index afd65c03d6bad7..71a79c36dc91b3 100644 --- a/src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs +++ b/src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs @@ -608,11 +608,11 @@ public void DefineMethodOverride(System.Reflection.MethodInfo methodInfoBody, Sy public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("P/Invoke marshalling may dynamically access members that could be trimmed.")] protected abstract System.Reflection.Emit.MethodBuilder DefinePInvokeMethodCore(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet); - public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[]? parameterTypes) { throw null; } - public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers) { throw null; } - public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Type returnType, System.Type[]? parameterTypes) { throw null; } - public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Type returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers) { throw null; } - protected abstract System.Reflection.Emit.PropertyBuilder DefinePropertyCore(string name, System.Reflection.PropertyAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers); + public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? parameterTypes) { throw null; } + public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers) { throw null; } + public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Type? returnType, System.Type[]? parameterTypes) { throw null; } + public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Type? returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers) { throw null; } + protected abstract System.Reflection.Emit.PropertyBuilder DefinePropertyCore(string name, System.Reflection.PropertyAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers); public System.Reflection.Emit.ConstructorBuilder DefineTypeInitializer() { throw null; } protected abstract System.Reflection.Emit.ConstructorBuilder DefineTypeInitializerCore(); public System.Reflection.Emit.FieldBuilder DefineUninitializedData(string name, int size, System.Reflection.FieldAttributes attributes) { throw null; } diff --git a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/PropertyBuilderImpl.cs b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/PropertyBuilderImpl.cs index d18289199a6273..68cc5a813451d3 100644 --- a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/PropertyBuilderImpl.cs +++ b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/PropertyBuilderImpl.cs @@ -26,7 +26,7 @@ internal sealed class PropertyBuilderImpl : PropertyBuilder internal List? _customAttributes; internal object? _defaultValue = DBNull.Value; - internal PropertyBuilderImpl(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers, TypeBuilderImpl containingType) + internal PropertyBuilderImpl(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers, TypeBuilderImpl containingType) { ArgumentException.ThrowIfNullOrEmpty(name); diff --git a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/TypeBuilderImpl.cs b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/TypeBuilderImpl.cs index 887ee1afb891f5..69cc149d30d5b8 100644 --- a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/TypeBuilderImpl.cs +++ b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/TypeBuilderImpl.cs @@ -408,7 +408,7 @@ protected override MethodBuilder DefinePInvokeMethodCore(string name, string dll } protected override PropertyBuilder DefinePropertyCore(string name, PropertyAttributes attributes, CallingConventions callingConvention, - Type returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, + Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers) { PropertyBuilderImpl property = new PropertyBuilderImpl(name, attributes, callingConvention, returnType, returnTypeRequiredCustomModifiers, diff --git a/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineEnum.cs b/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineEnum.cs index 0e9fb041ec4589..8bce42af9fac05 100644 --- a/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineEnum.cs +++ b/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineEnum.cs @@ -76,7 +76,7 @@ public void DefineEnum(string name, TypeAttributes visibility, Type underlyingTy Assert.Equal(FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName, createdUnderlyingField.Attributes); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [MemberData(nameof(DefineEnum_TestData))] public void DefineEnumPersistedAssembly(string name, TypeAttributes visibility, Type underlyingType) { diff --git a/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineType.cs b/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineType.cs index fb253350e523af..cc68471251d56c 100644 --- a/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineType.cs +++ b/src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineType.cs @@ -95,7 +95,7 @@ void Verify(TypeBuilder type, Module module) } } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [MemberData(nameof(TestData))] public void DefineTypePersistedAssembly(string name, TypeAttributes attributes, Type parent, PackingSize packingSize, int typesize, Type[] implementedInterfaces) { diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs index 6d25be45200ded..e656cbd62716db 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs @@ -60,7 +60,7 @@ public void DefineField(string name, Type fieldType, FieldAttributes attributes, } } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [MemberData(nameof(TestData))] public void DefineFieldPersistedAssembly(string name, Type fieldType, FieldAttributes attributes, FieldAttributes expectedAttributes) { @@ -108,7 +108,7 @@ public void DefineField_NameCollision() Assert.Throws(() => createdType.GetField("FieldName", Helpers.AllFlags)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] public void DefineField_NameCollisionPersistedAssembly() { PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); @@ -143,7 +143,7 @@ public void DefineField_65536Fields() Assert.Throws(() => type.CreateType()); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] public void DefineField_65536FieldsPersistedAssembly() { PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); @@ -178,7 +178,7 @@ public void DefineFieldMethod_LongName() Assert.Equal(Helpers.s_512Chars, method.Name); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] public void DefineFieldMethod_LongNamePersistedAssembly() { PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs index 0873068278d87d..89a076fc8be379 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs @@ -96,7 +96,7 @@ public void DefineMethod(string name, MethodAttributes attributes, CallingConven VerifyMethod(type4, method4, name, attributes, callingConvention, returnType, parameterTypes); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [MemberData(nameof(TestData))] public void DefineMethodPersistedAssembly(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) { @@ -139,7 +139,7 @@ public void DefineMethod_65536Methods() Assert.Throws(() => type.CreateType()); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] public void DefineMethod_65536MethodsPersistedAssembly() { PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilder(new AssemblyName("DefineMethod_65536MethodsPersistedAssembly")); diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs index 1fc18a1b099a1a..0311cc1f804298 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs @@ -39,7 +39,7 @@ public void DefineProperty(string name, PropertyAttributes attributes, Type retu PropertyBuilder property = type.DefineProperty(name, attributes, returnType, parameterTypes); Assert.Equal(name, property.Name); Assert.Equal(attributes, property.Attributes); - Assert.Equal(returnType, property.PropertyType); + Assert.Equal(returnType ?? typeof(void), property.PropertyType); Type createdType = type.CreateType(); Assert.Equal(type.AsType().GetProperties(Helpers.AllFlags), createdType.GetProperties(Helpers.AllFlags)); @@ -50,7 +50,7 @@ public void DefineProperty(string name, PropertyAttributes attributes, Type retu Assert.Equal(returnType ?? typeof(void), createdProperty.PropertyType); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [MemberData(nameof(TestData))] public void DefinePropertyPersistedAssembly(string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes, string expectedName, PropertyAttributes _) { @@ -93,7 +93,7 @@ public void DefineProperty_NameCollision() Assert.Throws(() => createdType.GetProperty("PropertyName", Helpers.AllFlags)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] public void DefineProperty_NameCollisionPersistedAssembly() { PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilderAndTypeBuilder(out TypeBuilder type); From 52fd746a059ac72792d820c86b379180ceda556d Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Thu, 1 Aug 2024 15:10:09 -0700 Subject: [PATCH 3/4] Update returnType nullability on Mono --- .../src/System/Reflection/Emit/RuntimePropertyBuilder.Mono.cs | 4 ++-- .../src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimePropertyBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimePropertyBuilder.Mono.cs index 5ac012a9bbbc20..73900ad7c21cf3 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimePropertyBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimePropertyBuilder.Mono.cs @@ -61,12 +61,12 @@ internal sealed partial class RuntimePropertyBuilder : PropertyBuilder private CallingConventions callingConvention; #endregion - internal RuntimePropertyBuilder(RuntimeTypeBuilder tb, string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[]? returnModReq, Type[]? returnModOpt, Type[]? parameterTypes, Type[][]? paramModReq, Type[][]? paramModOpt) + internal RuntimePropertyBuilder(RuntimeTypeBuilder tb, string name, PropertyAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? returnModReq, Type[]? returnModOpt, Type[]? parameterTypes, Type[][]? paramModReq, Type[][]? paramModOpt) { this.name = name; this.attrs = attributes; this.callingConvention = callingConvention; - this.type = returnType; + this.type = returnType ?? typeof(void); this.returnModReq = returnModReq; this.returnModOpt = returnModOpt; this.paramModReq = paramModReq; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs index a091b0dbbff87c..dad3e16a9ecb54 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs @@ -608,7 +608,7 @@ protected override FieldBuilder DefineFieldCore(string fieldName, Type type, Typ return res; } - protected override PropertyBuilder DefinePropertyCore(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers) + protected override PropertyBuilder DefinePropertyCore(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers, Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers) { check_name(nameof(name), name); if (parameterTypes != null) From 26f0bf186fd98f2ff9b8510c1d27468036fc3ae6 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Thu, 1 Aug 2024 15:37:47 -0700 Subject: [PATCH 4/4] Disable some tests on Mono --- .../tests/TypeBuilder/TypeBuilderDefineField.cs | 1 + .../tests/TypeBuilder/TypeBuilderDefineMethod.cs | 2 ++ .../tests/TypeBuilder/TypeBuilderDefineProperty.cs | 1 + 3 files changed, 4 insertions(+) diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs index e656cbd62716db..4b7613157c3c2a 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs @@ -131,6 +131,7 @@ public void DefineField_NameCollisionPersistedAssembly() } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/2389", TestRuntimes.Mono)] public void DefineField_65536Fields() { TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public); diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs index d76d5db53d9f61..1694945863f92b 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethod.cs @@ -125,6 +125,7 @@ public void DefineMethodPersistedAssembly(string name, MethodAttributes attribut } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/2389", TestRuntimes.Mono)] public void DefineMethod_65536Methods() { TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public); @@ -139,6 +140,7 @@ public void DefineMethod_65536Methods() } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/2389", TestRuntimes.Mono)] public void DefineMethod_65536MethodsPersistedAssembly() { PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyBuilder(new AssemblyName("DefineMethod_65536MethodsPersistedAssembly")); diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs index 0311cc1f804298..99d0d572eb418f 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs @@ -77,6 +77,7 @@ public void DefinePropertyPersistedAssembly(string name, PropertyAttributes attr } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/2389", TestRuntimes.Mono)] public void DefineProperty_NameCollision() { TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);