From 49fa010d4db7c49df8f5b6f6adf913518225fdeb Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Mon, 14 Jun 2021 10:03:41 -0500 Subject: [PATCH] Make JsonSerializer work when IsDynamicCodeSupported is false. (#54027) Use the non-Emit codepath if IsDynamicCodeSupported is false. --- .../src/System/Text/Json/Serialization/JsonSerializerOptions.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs index d6bb341..b37f11e 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs @@ -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(); -- 2.7.4