-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-System.Reflection.Emitbugsize-reductionIssues impacting final app size primary for size sensitive workloadsIssues impacting final app size primary for size sensitive workloads
Milestone
Description
When TypeBuilder encounters by-ref field it throws COMException. This seems to be the only reference to COMException and the behaviour is not consistent with other error handling for different type members.
runtime/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs
Lines 107 to 113 in cfb1335
| public void DefineField_ByRefFieldType_ThrowsCOMExceptionOnCreation() | |
| { | |
| TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public); | |
| type.DefineField("Name", typeof(int).MakeByRefType(), FieldAttributes.Public); | |
| Assert.Throws<COMException>(() => type.CreateTypeInfo()); | |
| } |
It should be replaced with ArgumentException as it's done for all other type members. Here is an example with events
runtime/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineEvent.cs
Lines 109 to 115 in cfb1335
| [Fact] | |
| public void DefineEvent_ByRefEventType_ThrowsArgumentException() | |
| { | |
| TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public); | |
| AssertExtensions.Throws<ArgumentException>(null, () => type.DefineEvent("Name", EventAttributes.None, typeof(int).MakeByRefType())); | |
| } |
Metadata
Metadata
Assignees
Labels
area-System.Reflection.Emitbugsize-reductionIssues impacting final app size primary for size sensitive workloadsIssues impacting final app size primary for size sensitive workloads