JsonSerializerOptions.AddContext<TContext> Method


Appends a new JsonSerializerContext to the metadata resolution of the current JsonSerializerOptions instance.

generic <typename TContext>
 where TContext : System::Text::Json::Serialization::JsonSerializerContextgcnew() void AddContext();
public void AddContext<TContext> () where TContext : System.Text.Json.Serialization.JsonSerializerContext, new();
member this.AddContext : unit -> unit (requires 'Context :> System.Text.Json.Serialization.JsonSerializerContext and 'Context : (new : unit -> 'Context))
Public Sub AddContext(Of TContext As {JsonSerializerContextNew}) ()

Type Parameters


The generic definition of the specified context type.


When serializing and deserializing types using the options instance, metadata for the types will be fetched from the context instance.

The methods supports adding multiple contexts per options instance. Metadata will be resolved in the order of configuration, similar to how Combine(IJsonTypeInfoResolver[]) resolves metadata.

Applies to