> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.nimbleapps.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# XmlSerializerOptions

> Provides options to be used with [XmlSerializer](/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer). This class cannot be inherited.

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

**Namespace:** CloudNimble.Text.Xml

## Syntax

```csharp theme={"dark"}
CloudNimble.Text.Xml.XmlSerializerOptions
```

## Summary

Provides options to be used with [XmlSerializer](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer.md). This class cannot be inherited.

## Usage

`XmlSerializerOptions` holds the settings that control how [`XmlSerializer`](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer) writes and reads XML: names, indentation, null handling, limits, converters, and where type metadata comes from. It is the counterpart of `JsonSerializerOptions`.

Create an instance once, set its properties in the initializer, and pass the same instance to every call:

```csharp theme={"dark"}
private static readonly XmlSerializerOptions s_compact = new()
{
    OmitXmlDeclaration = true,
    PropertyNamingPolicy = XmlNamingPolicy.CamelCase,
};
```

```csharp theme={"dark"}
output.WriteLine(XmlSerializer.Serialize(new InvoiceLine { Sku = "KB-101", Quantity = 2 }, s_compact));
output.WriteLine(XmlSerializer.Serialize(new InvoiceCustomer { Name = "Contoso", Email = "ap@contoso.example" }, s_compact));
```

The code produces the following output:

```xml theme={"dark"}
<invoiceLine><sku>KB-101</sku><quantity>2</quantity></invoiceLine>
<invoiceCustomer><name>Contoso</name><email>ap@contoso.example</email></invoiceCustomer>
```

There are three ways to get an instance:

* `new XmlSerializerOptions()` for the general defaults, or `new XmlSerializerOptions(XmlSerializerDefaults.Web)`, `XmlSerializerDefaults.Strict`, or `XmlSerializerDefaults.Bcl` for the other three sets.
* `new XmlSerializerOptions(existing)` to copy an instance and change the copy.
* The shared, read-only instances `XmlSerializerOptions.Default`, `XmlSerializerOptions.Web`, `XmlSerializerOptions.Strict`, and `XmlSerializerOptions.Bcl`.

An instance becomes read-only the first time it is used, or when you call `MakeReadOnly`. Every option, with its default, is listed in [Configure XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/guides/configure-options.md).

## Remarks

This class is the XML counterpart of `System.Text.Json.JsonSerializerOptions`.
An instance becomes read-only the first time it is used to serialize or deserialize, or when
[XmlSerializerOptions.MakeReadOnly](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#makereadonly) is called. Create one instance and reuse it: the converters and type info it
resolves are cached on the instance.

## Examples

The following examples show the three ways to get an options instance and what happens once an instance is in use.

### Use the built-in instances

```csharp theme={"dark"}
var line = new InvoiceLine { Sku = "KB-101", Quantity = 2 };

output.WriteLine(XmlSerializer.Serialize(line, XmlSerializerOptions.Default));
output.WriteLine(XmlSerializer.Serialize(line, XmlSerializerOptions.Web));
output.WriteLine(XmlSerializer.Serialize(line, XmlSerializerOptions.Strict));
```

The code produces the following output:

```xml theme={"dark"}
<?xml version="1.0" encoding="utf-8"?><InvoiceLine><Sku>KB-101</Sku><Quantity>2</Quantity></InvoiceLine>
<invoiceLine><sku>KB-101</sku><quantity>2</quantity></invoiceLine>
<?xml version="1.0" encoding="utf-8"?><InvoiceLine><Sku>KB-101</Sku><Quantity>2</Quantity></InvoiceLine>
```

### Start from a set of defaults and copy an instance

```csharp theme={"dark"}
var web = new XmlSerializerOptions(XmlSerializerDefaults.Web)
{
    WriteIndented = true,
    NewLine = "\n",
};

var line = new InvoiceLine { Sku = "KB-101", Quantity = 2 };
output.WriteLine(XmlSerializer.Serialize(line, web));

var flat = new XmlSerializerOptions(web) { WriteIndented = false };
output.WriteLine($"Source is read-only: {web.IsReadOnly}. Copy is read-only: {flat.IsReadOnly}.");
output.WriteLine(XmlSerializer.Serialize(line, flat));
```

The code produces the following output:

```text theme={"dark"}
<invoiceLine>
  <sku>KB-101</sku>
  <quantity>2</quantity>
</invoiceLine>
Source is read-only: True. Copy is read-only: False.
<invoiceLine><sku>KB-101</sku><quantity>2</quantity></invoiceLine>
```

### See when an instance becomes read-only

```csharp theme={"dark"}
var options = new XmlSerializerOptions { OmitXmlDeclaration = true };
output.WriteLine($"Before first use: {options.IsReadOnly}");

XmlSerializer.Serialize(new InvoiceLine { Sku = "KB-101", Quantity = 2 }, options);
output.WriteLine($"After first use: {options.IsReadOnly}");

try
{
    options.WriteIndented = true;
}
catch (InvalidOperationException ex)
{
    output.WriteLine(ex.Message);
}

var frozen = new XmlSerializerOptions();
frozen.MakeReadOnly();
output.WriteLine($"After MakeReadOnly: {frozen.IsReadOnly}");
```

The code produces the following output:

```text theme={"dark"}
Before first use: False
After first use: True
This XmlSerializerOptions instance is read-only.
After MakeReadOnly: True
```

[View the complete sample on GitHub](https://github.com/CloudNimble/XmlEssentials/blob/main/src/CloudNimble.XmlEssentials.Samples/13_ConfigureOptions.cs)

## Best Practices

* **Create options once.** Keep each instance in a `static readonly` field or a singleton. Never create one per call: the type metadata is cached on the instance, and a new instance starts with none.
* **Set everything in the initializer.** An instance can't be changed after its first use, so finish configuring it where you create it.
* **Use the same instance to read and to write.** Naming policies, the default property mapping, and the default namespace change the names the serializer looks for when it reads.
* **Call `MakeReadOnly` before you share an instance** with code that might otherwise change it before its first use.
* **Copy at startup, not per call.** A copy shares none of the source's cached metadata.
* **Set `NewLine` when the output must be identical on every operating system.** Its default is `Environment.NewLine`, and it is written for every line break: the ones `WriteIndented` adds and the ones inside values. It accepts `"\n"` and `"\r\n"`.
* **Set the layout options to match the files you already have.** `EmptyElementStyle` chooses between `<e/>`, `<e />` and `<e></e>`, and `AttributeStyle` with `AttributesPerLine` chooses how the attributes of a start tag are laid out. They change how the output looks, not what a reader gets from it, and they are passed to the writer under the same names.
* **Start from `XmlSerializerOptions.Strict` for XML you don't control,** and set `MaxDocumentByteCount`. See [Security](https://easyaf.nimbleapps.cloud/xmlessentials/guides/security.md).

## Considerations

An options instance carries a cache as well as settings, which explains most of what follows.

### Read-only after first use

Serializing, deserializing, or calling `GetTypeInfo` or `TryGetTypeInfo` makes the instance read-only. From then on every setter throws an `InvalidOperationException` with the message `This XmlSerializerOptions instance is read-only.`, and so do changes to `Converters` and `TypeInfoResolverChain`. The four static instances are read-only from the start. To change a read-only instance, copy it with `new XmlSerializerOptions(existing)`.

### The resolver is given, not assumed

`TypeInfoResolver` is `null` on a new instance. `GetTypeInfo` and `TryGetTypeInfo` use the resolver the instance has, and throw an `InvalidOperationException` when it has none. The members that need reflection give an instance without a resolver the reflection resolver: every `XmlSerializer` method that takes options, `GetConverter`, `MakeReadOnly(populateMissingResolver: true)`, and the four static instances. Each of them carries `RequiresUnreferencedCode` and `RequiresDynamicCode`, so a trimmed or Native AOT application gets a warning where it uses one. A copy made with `new XmlSerializerOptions(existing)` keeps a resolver you set, and not one that was only given: a copy of `XmlSerializerOptions.Web` has none, so a context you create from it becomes its resolver.

### The cache lives on the instance

Each instance caches the converter and the type metadata for every type it has been used with. A call with a new instance builds that metadata again, which costs many times what the call itself costs. See [Benchmarks](https://easyaf.nimbleapps.cloud/xmlessentials/benchmarks.md). The cache is never trimmed, so an application that keeps creating instances also keeps their metadata alive for as long as it holds them.

### Zero means the built-in default

`IndentSize`, `DefaultBufferSize`, and the `Max*` limits are `0` on a new instance. For each of them, `0` selects the built-in value: an indent of 2, a 16,384-byte buffer, a depth of 64, 1,000 attributes, 1,024 bytes for a name, 16,777,216 bytes for a text value, and 1,048,576 bytes for a comment. `MaxDocumentByteCount` is the exception: `0` means no limit.

### Closed types

`InferClosedTypePolymorphism` takes the derived types of a closed type from the list the compiler makes, for a type that declares none with `[XmlDerivedType<T>]`. It is `false` by default, as in System.Text.Json. A closed type needs C# 15 and .NET 11. See [Infer the derived types of a closed type](https://easyaf.nimbleapps.cloud/xmlessentials/guides/polymorphism.md#infer-the-derived-types-of-a-closed-type).

### Differences from JsonSerializerOptions

* `XmlSerializerDefaults.Web` sets only `PropertyNamingPolicy` to camelCase and `OmitXmlDeclaration` to `true`. It doesn't turn on case-insensitive matching.
* `RespectRequiredConstructorParameters` defaults to `true`.
* There are three naming policies for members instead of one: `PropertyNamingPolicy`, and `ElementNamingPolicy` and `AttributeNamingPolicy`, which override it for their kind of name.
* XML has options that JSON has no use for, such as `DefaultPropertyMapping`, `DefaultNamespace`, `OmitXmlDeclaration`, and `XmlVersion`.

### Thread safety

A read-only instance is meant to be shared between threads. See [Thread safety](https://easyaf.nimbleapps.cloud/xmlessentials/guides/thread-safety.md).

## Constructors

### &#x20;.ctor

Initializes a new instance of the [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) class.

#### Syntax

```csharp theme={"dark"}
public XmlSerializerOptions()
```

#### Remarks

The new instance uses the [XmlSerializerDefaults.General](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerDefaults.md) configuration.

### &#x20;.ctor

Initializes a new instance of the [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) class with a predefined set of options determined by the specified [XmlSerializerDefaults](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerDefaults.md).

#### Syntax

```csharp theme={"dark"}
public XmlSerializerOptions(CloudNimble.Text.Xml.XmlSerializerDefaults defaults)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `defaults` | `CloudNimble.Text.Xml.XmlSerializerDefaults` | One of the enumeration values that specifies the predefined set of options to use. |

### &#x20;.ctor

Initializes a new instance of the [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) class by copying the options from another instance.

#### Syntax

```csharp theme={"dark"}
public XmlSerializerOptions(CloudNimble.Text.Xml.XmlSerializerOptions options)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `options` | `CloudNimble.Text.Xml.XmlSerializerOptions` | The options instance to copy options from. |

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *options* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |

#### Remarks

The copy is not read-only and shares no cached state with *options*.

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public Object()
```

## Properties

### &#x20;AllowDuplicateProperties

Gets or sets a value that indicates whether a property can appear more than once in an object being deserialized.

#### Syntax

```csharp theme={"dark"}
public bool AllowDuplicateProperties { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if duplicate properties are allowed; [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) to throw an
[XmlException](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlException.md) when a property appears a second time. The default is [`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;AttributeNamingPolicy

Gets or sets the policy used to convert a member's name to an XML attribute name.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlNamingPolicy AttributeNamingPolicy { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlNamingPolicy?`
A naming policy for attribute names, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) to use [XmlSerializerOptions.PropertyNamingPolicy](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#propertynamingpolicy).
The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;AttributesPerLine

Gets or sets the number of attributes written to a line when [XmlSerializerOptions.AttributeStyle](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#attributestyle) is
[XmlAttributeStyle.PerLine](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlAttributeStyle.md).

#### Syntax

```csharp theme={"dark"}
public int AttributesPerLine { get; set; }
```

#### Property Value

Type: `int`
The number of attributes to a line. The default is 1. The value is not read when
[XmlSerializerOptions.AttributeStyle](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#attributestyle) is [XmlAttributeStyle.Inline](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlAttributeStyle.md).

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentOutOfRangeException` | The property is set to a value that is less than 1. |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;AttributeStyle

Gets or sets a value that specifies how the attributes of a start tag are laid out.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlAttributeStyle AttributeStyle { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlAttributeStyle`
One of the enumeration values. The default is [XmlAttributeStyle.Inline](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlAttributeStyle.md), which writes
every attribute on the line of the start tag.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

The value is passed to the writer as [XmlWriterOptions.AttributeStyle](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlWriterOptions.md#attributestyle).

### &#x20;Bcl

Gets a read-only, singleton instance of [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) that writes what
`System.Xml.Serialization.XmlSerializer` writes.

#### Syntax

```csharp theme={"dark"}
public static CloudNimble.Text.Xml.XmlSerializerOptions Bcl { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlSerializerOptions`
A read-only instance created with [XmlSerializerDefaults.Bcl](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerDefaults.md).

#### Examples

```csharp theme={"dark"}
string xml = XmlSerializer.Serialize(order, XmlSerializerOptions.Bcl);
```

#### Remarks

Use it when the documents have to stay the ones the old serializer wrote, for a consumer that already
reads them. It sets:

To change one of them, create an instance with [XmlSerializerOptions..ctor](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#.ctor)
and [XmlSerializerDefaults.Bcl](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerDefaults.md), which is not read-only.

### &#x20;CharHandling

Gets or sets a value that specifies how a [Char](https://learn.microsoft.com/dotnet/api/system.char) is written and read.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlCharHandling CharHandling { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlCharHandling`
One of the enumeration values that specifies whether a [Char](https://learn.microsoft.com/dotnet/api/system.char) is the character or its
number. The default is [XmlCharHandling.Character](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlCharHandling.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

The value applies to an element, an attribute and an item of a collection alike. Under
[XmlCharHandling.Number](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlCharHandling.md) a value that is not a number from 0 to 65535 is an error.

### &#x20;Converters

Gets the list of user-defined converters that were registered.

#### Syntax

```csharp theme={"dark"}
public System.Collections.Generic.IList<CloudNimble.Text.Xml.Serialization.XmlConverter> Converters { get; }
```

#### Property Value

Type: `System.Collections.Generic.IList<CloudNimble.Text.Xml.Serialization.XmlConverter>`
The list of custom converters.

#### Remarks

A converter in this list is used before an [XmlConverterAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlConverterAttribute.md) on the type and before the
built-in converters. The list cannot be changed after this instance has become read-only.

### &#x20;Default

Gets a read-only, singleton instance of [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) that uses the default configuration.

#### Syntax

```csharp theme={"dark"}
public static CloudNimble.Text.Xml.XmlSerializerOptions Default { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlSerializerOptions`
A read-only instance created with [XmlSerializerDefaults.General](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerDefaults.md).

### &#x20;DefaultBufferSize

Gets or sets the default buffer size, in bytes, to use when creating temporary buffers.

#### Syntax

```csharp theme={"dark"}
public int DefaultBufferSize { get; set; }
```

#### Property Value

Type: `int`
The default buffer size, in bytes. The default is 0, which means 16,384.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

This is the size of the first buffer rented when serializing, and of the first read buffer of
`DeserializeAsyncEnumerable`.

### &#x20;DefaultCollectionMapping

Gets or sets a value that specifies how collection members without a mapping attribute are mapped to
XML.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlCollectionMapping DefaultCollectionMapping { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlCollectionMapping`
One of the enumeration values that specifies whether the items of an unannotated collection member
are written as repeated elements or inside a wrapper element. The default is
[XmlCollectionMapping.Unwrapped](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlCollectionMapping.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

With [XmlCollectionMapping.Wrapped](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlCollectionMapping.md), a collection member is written as `[XmlArray]`
writes it: one element named for the member, with an element for each item named for the item's type.
An empty collection is an empty wrapper element. This is what
`System.Xml.Serialization.XmlSerializer` does by default.

`[XmlElement]` on a member writes its items with no wrapper under either value, and
`[XmlArray]` writes a wrapper under either value. `[XmlArrayItem]` names the items of a
wrapped collection, including one this property wraps. Dictionaries and `byte[]` are not
collections for this purpose. The same value is used to read.

### &#x20;DefaultIgnoreCondition

Gets or sets a value that determines when members are ignored during serialization or deserialization.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlIgnoreCondition DefaultIgnoreCondition { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.XmlIgnoreCondition`
One of the enumeration values that specifies when a member is ignored. The default is
[XmlIgnoreCondition.Never](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlIgnoreCondition.md).

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentException` | The value is [XmlIgnoreCondition.Always](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlIgnoreCondition.md), which would ignore every member. |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

An [XmlIgnoreAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlIgnoreAttribute.md) on a member overrides this value for that member. Every value but
[XmlIgnoreCondition.Always](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlIgnoreCondition.md) is accepted. [XmlIgnoreCondition.WhenWriting](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlIgnoreCondition.md) and
[XmlIgnoreCondition.WhenReading](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlIgnoreCondition.md) have no effect as the default for every member, as in
System.Text.Json: they apply only where an [XmlIgnoreAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlIgnoreAttribute.md) gives them.

### &#x20;DefaultNamespace

Gets or sets the namespace URI of the document element for types that do not specify one.

#### Syntax

```csharp theme={"dark"}
public string DefaultNamespace { get; set; }
```

#### Property Value

Type: `string?`
The namespace URI of the document element, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) for no namespace. The default is
[`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

A namespace set on the type with [XmlRootAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlRootAttribute.md) takes precedence over this value.

### &#x20;DefaultPropertyMapping

Gets or sets a value that specifies how members without a mapping attribute are mapped to XML.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlPropertyMapping DefaultPropertyMapping { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlPropertyMapping`
One of the enumeration values that specifies whether an unannotated member is written as a child element
or as an attribute. The default is [XmlPropertyMapping.Element](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlPropertyMapping.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

The default is [XmlPropertyMapping.Element](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlPropertyMapping.md): public properties become child elements,
matching JSON properties in System.Text.Json. Set [XmlPropertyMapping.Attribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlPropertyMapping.md) to write
unannotated simple members as XML attributes without annotating each one. Nested objects and
collections stay elements. `[XmlElement]`, `[XmlAttribute]`, and `[XmlText]` override
this per member.

### &#x20;DictionaryKeyPolicy

Gets or sets the policy used to convert a dictionary key's name to another format, such as camel-casing.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlNamingPolicy DictionaryKeyPolicy { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlNamingPolicy?`
A naming policy for dictionary keys, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) to use [XmlSerializerOptions.PropertyNamingPolicy](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#propertynamingpolicy).
The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;ElementNamingPolicy

Gets or sets the policy used to convert a type's or member's name to an XML element name.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlNamingPolicy ElementNamingPolicy { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlNamingPolicy?`
A naming policy for element names, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) to use [XmlSerializerOptions.PropertyNamingPolicy](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#propertynamingpolicy).
The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;EmitByteOrderMark

Gets or sets a value that indicates whether a UTF-8 byte order mark is written at the start of the output.

#### Syntax

```csharp theme={"dark"}
public bool EmitByteOrderMark { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if a UTF-8 byte order mark is written; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).
The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;EmptyElementStyle

Gets or sets a value that specifies how an element that has no content is written.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlEmptyElementStyle EmptyElementStyle { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlEmptyElementStyle`
One of the enumeration values. The default is [XmlEmptyElementStyle.SelfClosing](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlEmptyElementStyle.md), which
writes `<e/>`.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

The value is passed to the writer as [XmlWriterOptions.EmptyElementStyle](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlWriterOptions.md#emptyelementstyle).

### &#x20;EnumHandling

Gets or sets a value that specifies how enumeration values are written.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlEnumHandling EnumHandling { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlEnumHandling`
One of the enumeration values that specifies whether an enumeration value is written as its member name
or as its underlying integer. The default is [XmlEnumHandling.Name](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlEnumHandling.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;IgnoreReadOnlyFields

Gets or sets a value that indicates whether read-only fields are ignored during serialization and deserialization.

#### Syntax

```csharp theme={"dark"}
public bool IgnoreReadOnlyFields { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if read-only fields are ignored; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).
The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

A field is read-only if it is declared `readonly`. Fields are considered only when
[XmlSerializerOptions.IncludeFields](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#includefields) is [`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool). A collection or a dictionary is not ignored.

### &#x20;IgnoreReadOnlyProperties

Gets or sets a value that indicates whether read-only properties are ignored during serialization and deserialization.

#### Syntax

```csharp theme={"dark"}
public bool IgnoreReadOnlyProperties { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if read-only properties are ignored; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).
The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

A property is read-only if it has no `set` or `init` accessor. A
collection or a dictionary is not ignored: it is written from its getter, and filled through it when
[XmlSerializerOptions.PreferredObjectCreationHandling](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#preferredobjectcreationhandling) is [XmlObjectCreationHandling.Populate](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlObjectCreationHandling.md).

### &#x20;IncludeFields

Gets or sets a value that indicates whether public fields are handled during serialization and deserialization.

#### Syntax

```csharp theme={"dark"}
public bool IncludeFields { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if public fields are included; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).
The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;IndentCharacter

Gets or sets the indentation character used when [XmlSerializerOptions.WriteIndented](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#writeindented) is [`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Syntax

```csharp theme={"dark"}
public char IndentCharacter { get; set; }
```

#### Property Value

Type: `char`
The indentation character. The default is the space character.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;IndentSize

Gets or sets the indentation size used when [XmlSerializerOptions.WriteIndented](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#writeindented) is [`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Syntax

```csharp theme={"dark"}
public int IndentSize { get; set; }
```

#### Property Value

Type: `int`
The number of [XmlSerializerOptions.IndentCharacter](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#indentcharacter) characters written per nesting level. The default is 0, which means 2.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;InferClosedTypePolymorphism

Gets or sets a value that indicates whether the derived types of a closed type are inferred.

#### Syntax

```csharp theme={"dark"}
public bool InferClosedTypePolymorphism { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the derived types of a closed type that declares none are taken from its
closed hierarchy; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool). The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

A closed type is a class declared with the `closed` modifier, which needs C# 15 and
.NET 11. Its derived types are all in its own assembly, and the compiler lists them. A derived type is
written and read as if the closed type had an [XmlDerivedTypeAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlDerivedTypeAttribute.md) for it, with the
name of the derived type as its discriminator.

[XmlPolymorphicAttribute.InferClosedTypePolymorphism](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlPolymorphicAttribute.md#inferclosedtypepolymorphism) on a type takes precedence over this
value, and a type that declares derived types with [XmlDerivedTypeAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlDerivedTypeAttribute.md) has nothing
inferred. This is the counterpart of `JsonSerializerOptions.InferClosedTypePolymorphism`.

### &#x20;IsReadOnly

Gets a value that indicates whether the current instance has been locked for modification.

#### Syntax

```csharp theme={"dark"}
public bool IsReadOnly { get; private set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if this instance can no longer be changed; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).
The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

### &#x20;MaxAttributeCount

Gets or sets the maximum number of attributes allowed on one element.

#### Syntax

```csharp theme={"dark"}
public int MaxAttributeCount { get; set; }
```

#### Property Value

Type: `int`
The maximum number of attributes on one element. The default is 0, which means 1000.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;MaxCommentByteCount

Gets or sets the maximum size, in bytes, of the content of a comment that is read.

#### Syntax

```csharp theme={"dark"}
public int MaxCommentByteCount { get; set; }
```

#### Property Value

Type: `int`
The maximum size of a comment's content, in bytes. The default is 0, which means 1,048,576.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;MaxDepth

Gets or sets the maximum depth allowed when serializing or deserializing XML.

#### Syntax

```csharp theme={"dark"}
public int MaxDepth { get; set; }
```

#### Property Value

Type: `int`
The maximum element depth allowed when serializing or deserializing XML. The default is 0, which means 64.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;MaxDocumentByteCount

Gets or sets the maximum size, in bytes, of a document that is read.

#### Syntax

```csharp theme={"dark"}
public int MaxDocumentByteCount { get; set; }
```

#### Property Value

Type: `int`
The maximum document size, in bytes. The default is 0, which means the size is not limited.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;MaxNameByteCount

Gets or sets the maximum length, in bytes, of an XML name.

#### Syntax

```csharp theme={"dark"}
public int MaxNameByteCount { get; set; }
```

#### Property Value

Type: `int`
The maximum length of a name, in bytes. The default is 0, which means 1024.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;MaxTextByteCount

Gets or sets the maximum size of a text node, a CDATA section, an attribute value, or the data of a processing instruction that is read.

#### Syntax

```csharp theme={"dark"}
public int MaxTextByteCount { get; set; }
```

#### Property Value

Type: `int`
The maximum size of each, in UTF-8 bytes as they appear in the document. The default is 0, which means
16,777,216.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;MemberOrder

Gets or sets a value that specifies where the fields of a type come among its members.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlMemberOrder MemberOrder { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlMemberOrder`
One of the enumeration values that specifies whether the fields of a class come after its properties
or before them. The default is [XmlMemberOrder.PropertiesFirst](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlMemberOrder.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

The value matters only for a type with both, and only when [XmlSerializerOptions.IncludeFields](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#includefields) is
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) or a field is marked to be included. An explicit order on a member takes
precedence.

### &#x20;Namespaces

Gets or sets the namespace declarations that are written on the document element, each as a prefix
and the namespace URI it is bound to.

#### Syntax

```csharp theme={"dark"}
public System.Collections.Generic.IReadOnlyDictionary<string, string> Namespaces { get; set; }
```

#### Property Value

Type: `System.Collections.Generic.IReadOnlyDictionary<string, string>?`
The declarations, keyed by prefix, in the order they are written, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) for none.
An empty prefix is the default namespace. The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentException` | The property is set to declarations of which one cannot be written: a prefix that is not an XML name |
| without a colon, the `xmlns` prefix, the `xml` prefix or its namespace bound to anything but | |
| each other, the `xmlns` namespace, or a namespace URI that is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) or empty. | |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Examples

```csharp theme={"dark"}
var options = new XmlSerializerOptions { Namespaces = KnownNamespaces.Podcast };
string xml = XmlSerializer.Serialize(feed, options);
```

#### Remarks

Without this property the serializer declares a namespace where it is first needed and chooses how:
as the default namespace of an element, or with a generated prefix such as `ns1` for an attribute.
A namespace that is declared here is in scope for the whole document, so every element and attribute
in it is written with the prefix given here. A declaration is written whether or not anything uses it.
When two prefixes are bound to one namespace, the one declared last is used. The declarations are
written in the order given, with one exception: the declaration that names the namespace of the
document element itself comes first, because the element's start tag needs it.

The declarations are copied when the property is set. Use
[XmlDocument.DiscoverNamespaces](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlDocument.md#discovernamespaces) to take them from
an existing document, [KnownNamespaces](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/KnownNamespaces.md) for those of a well-known format, or
[XmlNamespaceDeclarationAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlNamespaceDeclarationAttribute.md) to state them on the type. These declarations take
precedence over the type's.

An empty prefix declares the default namespace on the document element, so an element with no
namespace of its own is in that namespace. When the document element has a namespace of its own that
is not this one and has no prefix declared, the two cannot both be written, and serialization throws an
[InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception).

The property affects writing only. When the serializer reads, it compares namespace URIs and never
prefixes.

### &#x20;NewLine

Gets or sets the line ending that is written.

#### Syntax

```csharp theme={"dark"}
public string NewLine { get; set; }
```

#### Property Value

Type: `string`
The line ending: `"\n"` or `"\r\n"`. The default is the value of [NewLine](https://learn.microsoft.com/dotnet/api/system.environment.newline).

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | The property is set to [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |
| `ArgumentOutOfRangeException` | The property is set to a value that is neither `"\n"` nor `"\r\n"`. |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;NumberHandling

Gets or sets a value that specifies whether the named floating-point literals `INF`, `-INF`, and `NaN` are read and written.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlNumberHandling NumberHandling { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.XmlNumberHandling`
One of the enumeration values that specifies how named floating-point literals are handled. The default is
[XmlNumberHandling.AllowNamedFloatingPointLiterals](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlNumberHandling.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;OmitXmlDeclaration

Gets or sets a value that indicates whether the XML declaration is omitted from the output.

#### Syntax

```csharp theme={"dark"}
public bool OmitXmlDeclaration { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the XML declaration is omitted; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).
The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;PreferredObjectCreationHandling

Gets or sets the preferred object creation handling for members when deserializing XML.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlObjectCreationHandling PreferredObjectCreationHandling { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.XmlObjectCreationHandling`
One of the enumeration values that specifies whether a member that already holds a value is given a new
one or has the value it holds populated. The default is [XmlObjectCreationHandling.Replace](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlObjectCreationHandling.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

The rules are those of `JsonSerializerOptions.PreferredObjectCreationHandling`. Under
[XmlObjectCreationHandling.Replace](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlObjectCreationHandling.md) a member with no setter is not read. Under
[XmlObjectCreationHandling.Populate](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlObjectCreationHandling.md) the items of a collection and the entries of a dictionary
are added to the instance the member holds, and the members of an object are set on it, whether or not the
member has a setter. A member that holds [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) is given a new instance when it has a setter.

The option applies only where a member can be populated. An array, an immutable or read-only collection, a
polymorphic type, a value with a custom converter, a value type with no setter, and every member of a type
that is created through a constructor with parameters are handled as under
[XmlObjectCreationHandling.Replace](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlObjectCreationHandling.md). [XmlObjectCreationHandlingAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlObjectCreationHandlingAttribute.md) sets the
handling of one member or one type and takes precedence.

[XmlObjectCreationHandling.Populate](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlObjectCreationHandling.md) cannot be combined with [XmlSerializerOptions.ReferenceHandler](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#referencehandler): a
type with a member to populate throws an [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) when it is first used.

### &#x20;PropertyNameCaseInsensitive

Gets or sets a value that indicates whether a property's name uses a case-insensitive comparison during deserialization.

#### Syntax

```csharp theme={"dark"}
public bool PropertyNameCaseInsensitive { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if property names are compared case-insensitively; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).
The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;PropertyNamingPolicy

Gets or sets the policy used to convert a type's or member's name to another format, such as camel-casing, when no more specific policy is set.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlNamingPolicy PropertyNamingPolicy { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlNamingPolicy?`
A naming policy, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) to leave names unchanged. The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

[XmlSerializerOptions.ElementNamingPolicy](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#elementnamingpolicy), [XmlSerializerOptions.AttributeNamingPolicy](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#attributenamingpolicy), and [XmlSerializerOptions.DictionaryKeyPolicy](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#dictionarykeypolicy)
each fall back to this policy when they are [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

### &#x20;ReadCommentHandling

Gets or sets a value that defines how comments are handled during deserialization.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlCommentHandling ReadCommentHandling { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlCommentHandling`
One of the enumeration values that indicates whether comments are allowed, disallowed, or skipped.
The default is [XmlCommentHandling.Skip](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlCommentHandling.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;ReferenceHandler

Gets or sets an object that specifies how object references are handled when reading and writing XML.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlReferenceHandler ReferenceHandler { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.XmlReferenceHandler?`
The reference handler, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if object references are not tracked. The default is
[`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;RespectNullableAnnotations

Gets or sets a value that indicates whether a [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) is refused for a member or constructor parameter annotated non-nullable.

#### Syntax

```csharp theme={"dark"}
public bool RespectNullableAnnotations { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if nullability annotations are respected; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).
The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

When this is [`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool), an element marked `xsi:nil="true"` for a member or constructor
parameter that does not accept [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) throws an [XmlException](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlException.md) when it is read, and
a member annotated as never returning [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) that holds one throws when it is written. A
[`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) that the ignore condition leaves out is not written and is not refused.

The rules are those of `JsonSerializerOptions.RespectNullableAnnotations`. The annotation of the member
decides, together with `[AllowNull]`, `[DisallowNull]`, `[MaybeNull]` and `[NotNull]`. A
member the document leaves out is not checked. The items of a collection, the values of a dictionary, the
document root, a member compiled without nullable annotations, and a member whose type is an unconstrained
type parameter are not checked either.

### &#x20;RespectRequiredConstructorParameters

Gets or sets a value that indicates whether non-optional constructor parameters must be present in the XML during deserialization.

#### Syntax

```csharp theme={"dark"}
public bool RespectRequiredConstructorParameters { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if an [XmlException](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlException.md) is thrown when the XML has no value for a constructor
parameter that has no default value; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool). The default is [`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;Strict

Gets a read-only, singleton instance of [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) that uses the strict configuration.

#### Syntax

```csharp theme={"dark"}
public static CloudNimble.Text.Xml.XmlSerializerOptions Strict { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlSerializerOptions`
A read-only instance created with [XmlSerializerDefaults.Strict](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerDefaults.md).

### &#x20;TypeInfoResolver

Gets or sets the [XmlTypeInfo](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md) contract resolver used by this instance.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver TypeInfoResolver { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver?`
The resolver that supplies [XmlTypeInfo](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md) metadata, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if none has been set.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

An instance that has none gets [DefaultXmlTypeInfoResolver.Instance](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/DefaultXmlTypeInfoResolver.md#instance) when it is first used by an
[XmlSerializer](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer.md) method that takes options, or by [XmlSerializerOptions.MakeReadOnly](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#makereadonly), if
[XmlSerializer.IsReflectionEnabledByDefault](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer.md#isreflectionenabledbydefault) is [`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool). Those members say that
they need reflection, and this property does not, so reading it never brings the reflection resolver into a
trimmed program. [XmlSerializerOptions.TypeInfoResolverChain](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolverchain) is a view of this resolver.

### &#x20;TypeInfoResolverChain

Gets the list of chained [XmlTypeInfo](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md) contract resolvers used by this instance.

#### Syntax

```csharp theme={"dark"}
public System.Collections.Generic.IList<CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver> TypeInfoResolverChain { get; }
```

#### Property Value

Type: `System.Collections.Generic.IList<CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver>`
The resolvers that make up [XmlSerializerOptions.TypeInfoResolver](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolver), in the order they are asked.

#### Remarks

The list is empty until a resolver has been set. Changing the list makes it the
[XmlSerializerOptions.TypeInfoResolver](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolver); setting [XmlSerializerOptions.TypeInfoResolver](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolver) replaces the list's content.

### &#x20;UnknownTypeHandling

Gets or sets a value that specifies how an element is read into a value declared as [Object](https://learn.microsoft.com/dotnet/api/system.object).

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlUnknownTypeHandling UnknownTypeHandling { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.XmlUnknownTypeHandling`
One of the enumeration values that specifies whether the element is read as an [XmlElement](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlElement.md) or
as an [XmlNode](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Nodes/XmlNode.md). The default is [XmlUnknownTypeHandling.XmlElement](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlUnknownTypeHandling.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

This is the counterpart of `JsonSerializerOptions.UnknownTypeHandling`. It applies wherever the
declared type is [Object](https://learn.microsoft.com/dotnet/api/system.object): a member, an item of a collection, a value of a dictionary, and the
document root. An element marked `xsi:nil="true"` is read as [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) under both values.
Writing is not affected: a value declared as [Object](https://learn.microsoft.com/dotnet/api/system.object) is written as the type it has.

### &#x20;UnmappedMemberHandling

Gets or sets a value that specifies how XML elements and attributes that cannot be mapped to a member are handled during deserialization.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlUnmappedMemberHandling UnmappedMemberHandling { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.XmlUnmappedMemberHandling`
One of the enumeration values that specifies whether an unmapped element or attribute is skipped or
rejected. The default is [XmlUnmappedMemberHandling.Skip](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlUnmappedMemberHandling.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;UtcOffsetHandling

Gets or sets a value that specifies how a [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset) whose offset is zero is written.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlUtcOffsetHandling UtcOffsetHandling { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlUtcOffsetHandling`
One of the enumeration values that specifies whether a zero offset is written as `+00:00` or as
`Z`. The default is [XmlUtcOffsetHandling.WriteOffset](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlUtcOffsetHandling.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

#### Remarks

Only writing changes: `Z`, `+00:00` and `-00:00` are all read as a zero offset under
either value. A [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime) is not affected; its [Kind](https://learn.microsoft.com/dotnet/api/system.datetime.kind) decides what
is written.

### &#x20;Web

Gets a read-only, singleton instance of [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) that uses the web configuration.

#### Syntax

```csharp theme={"dark"}
public static CloudNimble.Text.Xml.XmlSerializerOptions Web { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlSerializerOptions`
A read-only instance created with [XmlSerializerDefaults.Web](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerDefaults.md): camel-case names and no XML declaration.

### &#x20;WhitespaceHandling

Gets or sets a value that specifies how white-space-only text between elements is handled during deserialization.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlWhitespaceHandling WhitespaceHandling { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlWhitespaceHandling`
One of the enumeration values that specifies how the reader treats white-space-only text between elements.
The default is [XmlWhitespaceHandling.Insignificant](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlWhitespaceHandling.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;WriteIndented

Gets or sets a value that indicates whether XML should use pretty printing. By default, XML is serialized without any extra white space.

#### Syntax

```csharp theme={"dark"}
public bool WriteIndented { get; set; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if XML is pretty printed on serialization; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).
The default is [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

### &#x20;XmlVersion

Gets or sets the XML version of the output, which is written in the XML declaration.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlVersion XmlVersion { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlVersion`
One of the enumeration values that specifies the XML version of the output. The default is
[XmlVersion.Version10](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlVersion.md).

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The property is set after this instance has become read-only. |

## Methods

### &#x20;Equals Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual bool Equals(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;Equals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool Equals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;GetConverter

Returns the converter for the specified type.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlConverter GetConverter(System.Type typeToConvert)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `typeToConvert` | `System.Type` | The type to return a converter for. |

#### Returns

Type: `CloudNimble.Text.Xml.Serialization.XmlConverter`
The first converter that supports the given type.

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *typeToConvert* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |
| `NotSupportedException` | There is no compatible [XmlConverter](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlConverter.md) for *typeToConvert*. |
| `InvalidOperationException` | An [XmlConverterAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlConverterAttribute.md) or a converter factory for *typeToConvert* is misconfigured. |

#### Remarks

The first match wins: [XmlSerializerOptions.Converters](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#converters) in list order, then [XmlConverterAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlConverterAttribute.md)
on the type, then the built-in converters.

### &#x20;GetHashCode Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual int GetHashCode()
```

#### Returns

Type: `int`

### &#x20;GetType Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public System.Type GetType()
```

#### Returns

Type: `System.Type`

### &#x20;GetTypeInfo

Gets the [XmlTypeInfo](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md) contract metadata resolved by the current [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) instance for the specified type, and makes this instance read-only.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlTypeInfo GetTypeInfo(System.Type type)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `type` | `System.Type` | The type to resolve contract metadata for. |

#### Returns

Type: `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`
The contract metadata resolved for *type*.

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *type* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |
| `NotSupportedException` | [XmlSerializerOptions.TypeInfoResolver](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolver) has no contract metadata for *type*. |
| `InvalidOperationException` | No resolver is set and reflection-based serialization is disabled. |
| -or- | |
| The resolver returned contract metadata for a type other than *type*. | |

### &#x20;GetTypeInfo

Gets the `XmlTypeInfo`1\` contract metadata resolved by the current [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) instance for the type specified by a generic type parameter, and makes this instance read-only.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlTypeInfo<T> GetTypeInfo<T>()
```

#### Returns

Type: `CloudNimble.Text.Xml.Serialization.XmlTypeInfo<T>`
The contract metadata resolved for *T*.

#### Type Parameters

* `T` - The type to resolve contract metadata for.

#### Exceptions

| Exception | Description |
| - | - |
| `NotSupportedException` | [XmlSerializerOptions.TypeInfoResolver](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolver) has no contract metadata for *T*. |
| `InvalidOperationException` | No resolver is set and reflection-based serialization is disabled. |
| -or- | |
| The resolver returned contract metadata for a type other than *T*. | |

### &#x20;MakeReadOnly

Marks the current instance as read-only to prevent any further user modification.

#### Syntax

```csharp theme={"dark"}
public void MakeReadOnly()
```

#### Remarks

Afterwards, every property setter and any change to [XmlSerializerOptions.Converters](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#converters) or
[XmlSerializerOptions.TypeInfoResolverChain](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolverchain) throws an [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception).

### &#x20;MakeReadOnly

Marks the current instance as read-only to prevent any further user modification, and optionally gives
it the reflection-based resolver when it has none.

#### Syntax

```csharp theme={"dark"}
public void MakeReadOnly(bool populateMissingResolver)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `populateMissingResolver` | `bool` | [`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) to set [XmlSerializerOptions.TypeInfoResolver](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolver) to [DefaultXmlTypeInfoResolver.Instance](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/DefaultXmlTypeInfoResolver.md#instance) |
| when no resolver has been set and [XmlSerializer.IsReflectionEnabledByDefault](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer.md#isreflectionenabledbydefault) is | | |
| [`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool); [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) to leave it as it is. | | |

#### Remarks

This is the counterpart of `JsonSerializerOptions.MakeReadOnly(bool)` in System.Text.Json. The
[XmlSerializer](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer.md) methods that take options do the same on the first call.

### &#x20;MemberwiseClone Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
protected internal object MemberwiseClone()
```

#### Returns

Type: `object`

### &#x20;ReferenceEquals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool ReferenceEquals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;ToString Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual string ToString()
```

#### Returns

Type: `string?`

### &#x20;TryGetTypeInfo

Tries to get the [XmlTypeInfo](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md) contract metadata resolved by the current [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) instance for the specified type, and makes this instance read-only.

#### Syntax

```csharp theme={"dark"}
public bool TryGetTypeInfo(System.Type type, out CloudNimble.Text.Xml.Serialization.XmlTypeInfo typeInfo)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `type` | `System.Type` | The type to resolve contract metadata for. |
| `typeInfo` | `CloudNimble.Text.Xml.Serialization.XmlTypeInfo?` | When this method returns, contains the resolved contract metadata, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if [XmlSerializerOptions.TypeInfoResolver](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolver) has none for *type*. This parameter is treated as uninitialized. |

#### Returns

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the contract metadata for *type* was resolved; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *type* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |
| `InvalidOperationException` | No resolver is set and reflection-based serialization is disabled. |
| -or- | |
| The resolver returned contract metadata for a type other than *type*. | |

### &#x20;TryGetTypeInfo

Tries to get the `XmlTypeInfo`1\` contract metadata resolved by the current [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) instance for the type specified by a generic type parameter, and makes this instance read-only.

#### Syntax

```csharp theme={"dark"}
public bool TryGetTypeInfo<T>(out CloudNimble.Text.Xml.Serialization.XmlTypeInfo<T> typeInfo)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `typeInfo` | `CloudNimble.Text.Xml.Serialization.XmlTypeInfo<T>?` | When this method returns, contains the resolved contract metadata, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if [XmlSerializerOptions.TypeInfoResolver](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#typeinforesolver) has none for *T*. This parameter is treated as uninitialized. |

#### Returns

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the contract metadata for *T* was resolved; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Type Parameters

* `T` - The type to resolve contract metadata for.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | No resolver is set and reflection-based serialization is disabled. |
| -or- | |
| The resolver returned contract metadata for a type other than *T*. | |

## Related APIs

* CloudNimble.Text.Xml.XmlSerializer
* CloudNimble.Text.Xml.XmlSerializerDefaults
* CloudNimble.Text.Xml.XmlNamingPolicy
* CloudNimble.Text.Xml.XmlPropertyMapping
* CloudNimble.Text.Xml.XmlEnumHandling
* CloudNimble.Text.Xml.XmlCommentHandling
* CloudNimble.Text.Xml.XmlWhitespaceHandling
* CloudNimble.Text.Xml.XmlVersion
* CloudNimble.Text.Xml.Serialization.XmlIgnoreCondition
* CloudNimble.Text.Xml.Serialization.XmlUnmappedMemberHandling
* CloudNimble.Text.Xml.Serialization.XmlNumberHandling
* CloudNimble.Text.Xml.Serialization.XmlReferenceHandler
* CloudNimble.Text.Xml.Serialization.XmlConverter
* CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.