You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/compatibility/serialization/7.0/reflection-fallback.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,21 @@ The previous behavior violates the principle of least surprise and ultimately de
74
74
75
75
## Recommended action
76
76
77
-
You might depend on the previous behavior, either intentionally or unintentionally. As such, you can use the following workaround to continue to fall back to reflection-based serialization when necessary:
77
+
You might depend on the previous behavior, either intentionally or unintentionally. The recommended course of action is to update your <xref:System.Text.Json.Serialization.JsonSerializerContext> definition so that it includes all type dependencies:
This will let your application take full advantage of the benefits of source generation, including trim safety.
86
+
87
+
In certain cases, however, making such a change might not be practical or possible. Even though it's not recommended, there are a couple of ways you can re-enable reflection fallback in your source-generated serializer.
88
+
89
+
### Use a custom contract resolver
90
+
91
+
You can use the new contract customization feature to build a custom contract resolver that falls back to reflection-based resolution where required:
options.GetConverter(typeof(Poco2)); // Returns the reflection-based converter.
87
101
```
88
102
103
+
### Use an AppContext switch
104
+
105
+
Starting in .NET 7 RC 2, you can re-enable reflection fallback globally using the provided AppContext compatibility switch. Add the following entry to your application's project file to re-enable reflection fallback for all source-generated contexts in your app. For more information on using AppContext switches, see the article on [.NET runtime configuration settings](../../../runtime-config/index.md).
0 commit comments