Make JsonSerializer work when IsDynamicCodeSupported is false. (#54027)
authorEric Erhardt <eric.erhardt@microsoft.com>
Mon, 14 Jun 2021 15:03:41 +0000 (10:03 -0500)
committerGitHub <noreply@github.com>
Mon, 14 Jun 2021 15:03:41 +0000 (10:03 -0500)
Use the non-Emit codepath if IsDynamicCodeSupported is false.

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs

index d6bb341..b37f11e 100644 (file)
@@ -559,7 +559,12 @@ namespace System.Text.Json
             {
                 if (_memberAccessorStrategy == null)
                 {
-#if NETFRAMEWORK || NETCOREAPP
+#if NETCOREAPP
+                    // if dynamic code isn't supported, fallback to reflection
+                    _memberAccessorStrategy = RuntimeFeature.IsDynamicCodeSupported ?
+                        new ReflectionEmitMemberAccessor() :
+                        new ReflectionMemberAccessor();
+#elif NETFRAMEWORK
                     _memberAccessorStrategy = new ReflectionEmitMemberAccessor();
 #else
                     _memberAccessorStrategy = new ReflectionMemberAccessor();