From: Eric Erhardt Date: Mon, 14 Jun 2021 15:03:41 +0000 (-0500) Subject: Make JsonSerializer work when IsDynamicCodeSupported is false. (#54027) X-Git-Tag: submit/tizen/20210909.063632~787 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49fa010d4db7c49df8f5b6f6adf913518225fdeb;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Make JsonSerializer work when IsDynamicCodeSupported is false. (#54027) Use the non-Emit codepath if IsDynamicCodeSupported is false. --- 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();