# NetworkEndpointSnapshotList Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [NetworkEndpointSnapshotList](/reference/api/csharp/aspire.hosting/networkendpointsnapshotlist.md)
- Kind: `Methods`
- Members: `4`

Holds a list of [NetworkEndpointSnapshot](/reference/api/csharp/aspire.hosting/networkendpointsnapshot.md) for an Endpoint, providing thread-safe enumeration and addition.

## AddOrUpdateAllocatedEndpoint(NetworkIdentifier, AllocatedEndpoint)

- Name: `AddOrUpdateAllocatedEndpoint(NetworkIdentifier, AllocatedEndpoint)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/EndpointAnnotation.cs#L334-L340)

Adds or updates an AllocatedEndpoint value associated with a specific network in the snapshot list.

```csharp
public class NetworkEndpointSnapshotList
{
    public void AddOrUpdateAllocatedEndpoint(
        NetworkIdentifier networkID,
        AllocatedEndpoint endpoint)
    {
        // ...
    }
}
```

## Parameters

- `networkID` ([NetworkIdentifier](/reference/api/csharp/aspire.hosting/networkidentifier.md))
- `endpoint` ([AllocatedEndpoint](/reference/api/csharp/aspire.hosting/allocatedendpoint.md))

## GetAllocatedEndpointAsync(NetworkIdentifier, CancellationToken)

- Name: `GetAllocatedEndpointAsync(NetworkIdentifier, CancellationToken)`
- Returns: [Task<AllocatedEndpoint>](/reference/api/csharp/aspire.hosting/allocatedendpoint.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/EndpointAnnotation.cs#L347-L348)

Gets an AllocatedEndpoint for a given network ID, waiting for it to appear if it is not already present.

```csharp
public class NetworkEndpointSnapshotList
{
    public Task<AllocatedEndpoint> GetAllocatedEndpointAsync(
        NetworkIdentifier networkID,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `networkID` ([NetworkIdentifier](/reference/api/csharp/aspire.hosting/networkidentifier.md))
- `cancellationToken` (`CancellationToken`) `optional`

## GetEnumerator

- Name: `GetEnumerator`
- Returns: [IEnumerator<NetworkEndpointSnapshot>](/reference/api/csharp/aspire.hosting/networkendpointsnapshot.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/EndpointAnnotation.cs#L304)

Provides a thread-safe enumerator over the network endpoint snapshots.

```csharp
public class NetworkEndpointSnapshotList
{
    public IEnumerator<NetworkEndpointSnapshot> GetEnumerator()
    {
        // ...
    }
}
```

## TryAdd(NetworkIdentifier, ValueSnapshot<AllocatedEndpoint>)

> **Obsolete:** This method is for internal use only and will be marked internal in a future Aspire release. Use AddOrUpdateAllocatedEndpoint instead.

- Name: `TryAdd(NetworkIdentifier, ValueSnapshot<AllocatedEndpoint>)`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/EndpointAnnotation.cs#L318-L327)

Adds an AllocatedEndpoint snapshot for a specific network if one does not already exist.

```csharp
public class NetworkEndpointSnapshotList
{
    public bool TryAdd(
        NetworkIdentifier networkID,
        ValueSnapshot<AllocatedEndpoint> snapshot)
    {
        // ...
    }
}
```

## Parameters

- `networkID` ([NetworkIdentifier](/reference/api/csharp/aspire.hosting/networkidentifier.md))
- `snapshot` (`ValueSnapshot<AllocatedEndpoint>`)
