diff --git a/src/libraries/System.Reflection.Emit/src/Resources/Strings.resx b/src/libraries/System.Reflection.Emit/src/Resources/Strings.resx
index e425a272ac097..96643e5d40b0e 100644
--- a/src/libraries/System.Reflection.Emit/src/Resources/Strings.resx
+++ b/src/libraries/System.Reflection.Emit/src/Resources/Strings.resx
@@ -195,4 +195,7 @@
Only 'OpCode.Switch' can be used.
+
+ The specified opcode cannot be passed to EmitCall.
+
\ No newline at end of file
diff --git a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/FieldBuilderImpl.cs b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/FieldBuilderImpl.cs
index 39e8881c2ab8c..54c24aa7bdb92 100644
--- a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/FieldBuilderImpl.cs
+++ b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/FieldBuilderImpl.cs
@@ -7,8 +7,6 @@
using System.Globalization;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
-using System.Runtime.InteropServices;
-using System.Runtime.InteropServices.Marshalling;
namespace System.Reflection.Emit
{
@@ -23,6 +21,7 @@ internal sealed class FieldBuilderImpl : FieldBuilder
internal int _offset;
internal List? _customAttributes;
internal object? _defaultValue = DBNull.Value;
+ internal FieldDefinitionHandle _handle;
internal FieldBuilderImpl(TypeBuilderImpl typeBuilder, string fieldName, Type type, FieldAttributes attributes)
{
@@ -107,7 +106,7 @@ protected override void SetCustomAttributeCore(ConstructorInfo con, ReadOnlySpan
return;
case "System.Runtime.InteropServices.MarshalAsAttribute":
_attributes |= FieldAttributes.HasFieldMarshal;
- _marshallingData = MarshallingData.CreateMarshallingData(con, binaryAttribute, isField : true);
+ _marshallingData = MarshallingData.CreateMarshallingData(con, binaryAttribute, isField: true);
return;
}
@@ -124,7 +123,7 @@ protected override void SetOffsetCore(int iOffset)
#region MemberInfo Overrides
- public override int MetadataToken => throw new NotImplementedException();
+ public override int MetadataToken => _handle == default ? 0 : MetadataTokens.GetToken(_handle);
public override Module Module => _typeBuilder.Module;
diff --git a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ILGeneratorImpl.cs b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ILGeneratorImpl.cs
index e7331233adb3d..75e06e19f87c4 100644
--- a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ILGeneratorImpl.cs
+++ b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ILGeneratorImpl.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
+using System.Diagnostics;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices;
@@ -19,6 +20,7 @@ internal sealed class ILGeneratorImpl : ILGenerator
private int _currentStack;
private List _locals = new();
private Dictionary