# CommandResults Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [CommandResults](/reference/api/csharp/aspire.hosting/commandresults.md)
- Kind: `Methods`
- Members: `10`

A factory for [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md).

## Canceled

- Name: `Canceled`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L279)

Produces a canceled result.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Canceled()
    {
        // ...
    }
}
```

## Failure(string?)

- Name: `Failure(string?)`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L259)

Produces an unsuccessful result with an error message.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Failure(
        string? errorMessage = null)
    {
        // ...
    }
}
```

## Parameters

- `errorMessage` (`string?`) `optional`
  An optional error message.

## Failure(string, string, CommandResultFormat)

- Name: `Failure(string, string, CommandResultFormat)`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L267)

Produces an unsuccessful result with an error message and result data.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Failure(
        string errorMessage,
        string result,
        CommandResultFormat resultFormat = CommandResultFormat.Text)
    {
        // ...
    }
}
```

## Parameters

- `errorMessage` (`string`)
  The error message.
- `result` (`string`)
  The result data.
- `resultFormat` ([CommandResultFormat](/reference/api/csharp/aspire.hosting/commandresultformat.md)) `optional`
  The format of the result data. Defaults to [CommandResultFormat.Text](/reference/api/csharp/aspire.hosting/commandresultformat/fields.md).

## Failure(string, CommandResultData)

- Name: `Failure(string, CommandResultData)`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L274)

Produces an unsuccessful result with an error message and a value.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Failure(
        string errorMessage,
        CommandResultData value)
    {
        // ...
    }
}
```

## Parameters

- `errorMessage` (`string`)
  The error message.
- `value` ([CommandResultData](/reference/api/csharp/aspire.hosting/commandresultdata.md))
  The value produced by the command.

## Failure(Exception)

- Name: `Failure(Exception)`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L285)

Produces an unsuccessful result from an `Exception`. `Exception.Message` is used as the error message.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Failure(
        Exception exception)
    {
        // ...
    }
}
```

## Parameters

- `exception` (`Exception`)
  The exception to get the error message from.

## Success

- Name: `Success`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L219)

Produces a success result.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Success()
    {
        // ...
    }
}
```

## Success(string)

- Name: `Success(string)`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L224)

Produces a success result.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Success(
        string message)
    {
        // ...
    }
}
```

## Parameters

- `message` (`string`)

## Success(string, string, CommandResultFormat)

- Name: `Success(string, string, CommandResultFormat)`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L232)

Produces a success result with a message and result data.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Success(
        string message,
        string result,
        CommandResultFormat resultFormat = CommandResultFormat.Text)
    {
        // ...
    }
}
```

## Parameters

- `message` (`string`)
  The message associated with the result.
- `result` (`string`)
  The result data.
- `resultFormat` ([CommandResultFormat](/reference/api/csharp/aspire.hosting/commandresultformat.md)) `optional`
  The format of the result data. Defaults to [CommandResultFormat.Text](/reference/api/csharp/aspire.hosting/commandresultformat/fields.md).

## Success(string, string, CommandResultFormat, bool)

- Name: `Success(string, string, CommandResultFormat, bool)`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L246)

Produces a success result with a message and result data.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Success(
        string message,
        string result,
        CommandResultFormat resultFormat,
        bool displayImmediately)
    {
        // ...
    }
}
```

## Parameters

- `message` (`string`)
  The message associated with the result.
- `result` (`string`)
  The result data.
- `resultFormat` ([CommandResultFormat](/reference/api/csharp/aspire.hosting/commandresultformat.md))
  The format of the result data.
- `displayImmediately` (`bool`)
  A value indicating whether the result data should be displayed immediately in the dashboard.

## Remarks

When `displayImmediately` is `true`, the dashboard opens the result dialog automatically when the command completes. Other clients can still read the result data from [ExecuteCommandResult.Data](/reference/api/csharp/aspire.hosting/executecommandresult/properties.md#data).

## Success(string, CommandResultData)

- Name: `Success(string, CommandResultData)`
- Modifiers: `static`
- Returns: [ExecuteCommandResult](/reference/api/csharp/aspire.hosting/executecommandresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L253)

Produces a success result with a message and a value.

```csharp
public static class CommandResults
{
    public static ExecuteCommandResult Success(
        string message,
        CommandResultData value)
    {
        // ...
    }
}
```

## Parameters

- `message` (`string`)
  The message associated with the result.
- `value` ([CommandResultData](/reference/api/csharp/aspire.hosting/commandresultdata.md))
  The value produced by the command.
