@@ -20,6 +20,7 @@ internal static class TomlTypeInfoResolverPipeline
2020 private const string ReflectionBasedSerializationMessage =
2121 "Reflection-based TOML serialization is not compatible with trimming/NativeAOT. " +
2222 "Use a source-generated TomlSerializerContext or pass a TomlTypeInfo instance." ;
23+ private const string ReflectionSwitchName = TomlSerializerFeatureSwitches . ReflectionSwitchName ;
2324
2425 private static readonly ConditionalWeakTable < TomlSerializerOptions , ConcurrentDictionary < Type , TomlTypeInfo > > CacheByOptions = new ( ) ;
2526
@@ -81,7 +82,7 @@ private static TomlTypeInfo ResolveUncached(TomlSerializerOptions options, Type
8182 $ "Dictionaries must have string keys to be representable as TOML tables. Type '{ type . FullName } ' is not supported without a custom converter.") ;
8283 }
8384
84- if ( TomlSerializerFeatureSwitches . IsReflectionEnabledByDefaultCalculated )
85+ if ( TomlSerializer . IsReflectionEnabledByDefault )
8586 {
8687 var typeInfo = ResolveFromReflection ( options , type ) ;
8788 return TomlPolymorphicTypeInfo . TryWrap ( typeInfo ) ;
@@ -94,8 +95,9 @@ private static TomlTypeInfo ResolveUncached(TomlSerializerOptions options, Type
9495 }
9596
9697 throw new TomlException (
97- $ "No TOML metadata is available for type '{ type . FullName } '. " +
98- $ "Provide { nameof ( TomlSerializerOptions ) } .{ nameof ( TomlSerializerOptions . TypeInfoResolver ) } (source generation) or a custom resolver.") ;
98+ $ "Reflection serialization is disabled and no TOML metadata was found for type '{ type . FullName } '. " +
99+ $ "Provide { nameof ( TomlSerializerOptions ) } .{ nameof ( TomlSerializerOptions . TypeInfoResolver ) } (source generation) or a custom resolver, " +
100+ $ "or enable the '{ ReflectionSwitchName } ' AppContext switch.") ;
99101 }
100102
101103 [ RequiresUnreferencedCode ( ReflectionBasedSerializationMessage ) ]
0 commit comments