diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
index bbdccc6cd2eed4..64669dd5458f78 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
@@ -21,7 +21,7 @@ public static partial class Marshal
///
/// IUnknown is {00000000-0000-0000-C000-000000000046}
///
- internal static Guid IID_IUnknown = new Guid(0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
+ internal static readonly Guid IID_IUnknown = new Guid(0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
#endif //FEATURE_COMINTEROP
internal static int SizeOfHelper(RuntimeType t, [MarshalAs(UnmanagedType.Bool)] bool throwIfNotMarshalable)
@@ -929,7 +929,7 @@ public static object BindToMoniker(string monikerName)
ThrowExceptionForHR(MkParseDisplayName(bindctx, monikerName, out _, out IntPtr pmoniker));
try
{
- ThrowExceptionForHR(BindMoniker(pmoniker, 0, ref IID_IUnknown, out IntPtr ptr));
+ ThrowExceptionForHR(BindMoniker(pmoniker, 0, in IID_IUnknown, out IntPtr ptr));
try
{
return GetObjectForIUnknown(ptr);
@@ -956,7 +956,7 @@ public static object BindToMoniker(string monikerName)
private static partial int MkParseDisplayName(IntPtr pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IntPtr ppmk);
[LibraryImport(Interop.Libraries.Ole32)]
- private static partial int BindMoniker(IntPtr pmk, uint grfOpt, ref Guid iidResult, out IntPtr ppvResult);
+ private static partial int BindMoniker(IntPtr pmk, uint grfOpt, in Guid iidResult, out IntPtr ppvResult);
[SupportedOSPlatform("windows")]
public static void ChangeWrapperHandleStrength(object otp, bool fIsWeak)
diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs
index 7ce239610a7ab6..b2140c6b00cb69 100644
--- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs
+++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs
@@ -405,7 +405,7 @@ public static void FailedAllocation(MethodTable* pEEType, bool fIsOverflow)
}
#if !INPLACE_RUNTIME
- private static OutOfMemoryException s_theOOMException = new OutOfMemoryException();
+ private static readonly OutOfMemoryException s_theOOMException = new OutOfMemoryException();
// MRT exports GetRuntimeException for the few cases where we have a helper that throws an exception
// and may be called by either MRT or other classlibs and that helper needs to throw an exception.
diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs
index 0161e8c47c1508..6c371a83d687f3 100644
--- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs
+++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs
@@ -35,7 +35,7 @@ internal static class TypeCast
private const int MaximumCacheSize = 4096; // 4096 * sizeof(CastCacheEntry) is 98304 bytes on 64bit. We will rarely need this much though.
#endif // DEBUG
- private static CastCache s_castCache = new CastCache(InitialCacheSize, MaximumCacheSize);
+ private static readonly CastCache s_castCache = new CastCache(InitialCacheSize, MaximumCacheSize);
[Flags]
internal enum AssignmentVariation
diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs
index e5bfe42e497694..6b246e4ee4567e 100644
--- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs
+++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs
@@ -695,7 +695,7 @@ public override int GetHashCode()
internal sealed class CustomMarshallerTable : ConcurrentUnifier
{
- internal static CustomMarshallerTable s_customMarshallersTable = new CustomMarshallerTable();
+ internal static readonly CustomMarshallerTable s_customMarshallersTable = new CustomMarshallerTable();
protected override unsafe object Factory(CustomMarshallerKey key)
{
diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/RuntimeMethodHandleInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/RuntimeMethodHandleInfo.cs
index 90b0f242a4188b..41aa17cdcbfdae 100644
--- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/RuntimeMethodHandleInfo.cs
+++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/RuntimeMethodHandleInfo.cs
@@ -12,8 +12,8 @@ namespace Internal.Runtime.CompilerServices
{
public class MethodNameAndSignature
{
- public string Name { get; private set; }
- public RuntimeSignature Signature { get; private set; }
+ public string Name { get; }
+ public RuntimeSignature Signature { get; }
public MethodNameAndSignature(string name, RuntimeSignature signature)
{
diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs
index 9589edaab42b3d..7db1728b3128e1 100644
--- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs
+++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs
@@ -31,7 +31,7 @@ internal static unsafe RuntimeType GetTypeFromMethodTable(MethodTable* pMT)
private static class AllocationLockHolder
{
- public static Lock AllocationLock = new Lock(useTrivialWaits: true);
+ public static readonly Lock AllocationLock = new Lock(useTrivialWaits: true);
}
[MethodImpl(MethodImplOptions.NoInlining)]
diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/MethodInvokerWithMethodInvokeInfo.cs b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/MethodInvokerWithMethodInvokeInfo.cs
index df5715e2d119d6..6bff16c340a92d 100644
--- a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/MethodInvokerWithMethodInvokeInfo.cs
+++ b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/MethodInvokerWithMethodInvokeInfo.cs
@@ -62,6 +62,6 @@ internal static MethodBaseInvoker CreateMethodInvoker(RuntimeTypeHandle declarin
return new InstanceMethodInvoker(methodInvokeInfo, declaringTypeHandle);
}
- internal MethodInvokeInfo MethodInvokeInfo { get; private set; }
+ internal MethodInvokeInfo MethodInvokeInfo { get; }
}
}
diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LockFreeObjectInterner.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LockFreeObjectInterner.cs
index 52593e30bb48dd..e4897f9854e33a 100644
--- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LockFreeObjectInterner.cs
+++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LockFreeObjectInterner.cs
@@ -8,7 +8,7 @@ namespace Internal.TypeSystem
{
public class LockFreeObjectInterner : LockFreeReaderHashtableOfPointers