From 41333f0b0c732d57717f482c3178ca84562c55f9 Mon Sep 17 00:00:00 2001 From: Toni Solarin-Sodara Date: Tue, 6 Oct 2020 22:55:08 +0100 Subject: [PATCH] Ensure static constructors of compiled in types are run (#5011) --- .../Internal/Runtime/Interpreter/ILInterpreter.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/System.Private.Interpreter/src/Internal/Runtime/Interpreter/ILInterpreter.cs b/src/System.Private.Interpreter/src/Internal/Runtime/Interpreter/ILInterpreter.cs index 2225c7ee594..3ff44a64417 100644 --- a/src/System.Private.Interpreter/src/Internal/Runtime/Interpreter/ILInterpreter.cs +++ b/src/System.Private.Interpreter/src/Internal/Runtime/Interpreter/ILInterpreter.cs @@ -2893,6 +2893,12 @@ private void InterpretLoadStaticField(FieldDesc field) nativeFormatField.Handle, out FieldAccessMetadata fieldAccessMetadata); + IntPtr cctorContext = TypeLoaderEnvironment.TryGetStaticClassConstructionContext(field.OwningType.GetRuntimeTypeHandle()); + if (cctorContext != IntPtr.Zero) + { + RuntimeAugments.EnsureClassConstructorRun(cctorContext); + } + FieldTableFlags fieldFlags = fieldAccessMetadata.Flags & FieldTableFlags.StorageClass; if (fieldFlags == FieldTableFlags.NonGCStatic) { @@ -3075,6 +3081,12 @@ private void InterpretStoreStaticField(FieldDesc field) nativeFormatField.Handle, out FieldAccessMetadata fieldAccessMetadata); + IntPtr cctorContext = TypeLoaderEnvironment.TryGetStaticClassConstructionContext(field.OwningType.GetRuntimeTypeHandle()); + if (cctorContext != IntPtr.Zero) + { + RuntimeAugments.EnsureClassConstructorRun(cctorContext); + } + FieldTableFlags fieldFlags = fieldAccessMetadata.Flags & FieldTableFlags.StorageClass; if (fieldFlags == FieldTableFlags.NonGCStatic) {