XElement.LoadAsync Method

Definition

Overloads

LoadAsync(Stream, LoadOptions, CancellationToken)

Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space.

LoadAsync(TextReader, LoadOptions, CancellationToken)

Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space.

LoadAsync(XmlReader, LoadOptions, CancellationToken)

Asynchronously creates a new XElement and initializes its underlying XML tree using the specified XML reader, optionally preserving white space.

LoadAsync(Stream, LoadOptions, CancellationToken)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space.

C#
public static System.Threading.Tasks.Task<System.Xml.Linq.XElement> LoadAsync(System.IO.Stream stream, System.Xml.Linq.LoadOptions options, System.Threading.CancellationToken cancellationToken);

Parameters

stream
Stream

The stream containing the raw XML to read.

options
LoadOptions

A bitwise combination of the enumeration values that specify the load options to parse the XML.

cancellationToken
CancellationToken

A token that can be used to request cancellation of the asynchronous operation.

Returns

A new XElement containing the contents of the specified stream.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

If options is set to PreserveWhitespace, then the IgnoreWhitespace property is set to false.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Load(Stream, LoadOptions).

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

LoadAsync(TextReader, LoadOptions, CancellationToken)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space.

C#
public static System.Threading.Tasks.Task<System.Xml.Linq.XElement> LoadAsync(System.IO.TextReader textReader, System.Xml.Linq.LoadOptions options, System.Threading.CancellationToken cancellationToken);

Parameters

textReader
TextReader

A reader containing the raw XML to read.

options
LoadOptions

A bitwise combination of the enumeration values that specify the load options to parse the XML.

cancellationToken
CancellationToken

A token that can be used to request cancellation of the asynchronous operation.

Returns

A new XElement containing the contents of the specified reader.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

If options is set to PreserveWhitespace, then the IgnoreWhitespace property is set to false.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Load(TextReader, LoadOptions).

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

LoadAsync(XmlReader, LoadOptions, CancellationToken)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Asynchronously creates a new XElement and initializes its underlying XML tree using the specified XML reader, optionally preserving white space.

C#
public static System.Threading.Tasks.Task<System.Xml.Linq.XElement> LoadAsync(System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options, System.Threading.CancellationToken cancellationToken);

Parameters

reader
XmlReader

A reader containing the XML to be read.

options
LoadOptions

A bitwise combination of the enumeration values that specify the load options to parse the XML.

cancellationToken
CancellationToken

A token that can be used to request cancellation of the asynchronous operation.

Returns

A new XElement containing the contents of the specified reader.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Load(XmlReader, LoadOptions).

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1