# CommandResults Methods

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

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L188)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L168)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L176)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L183)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L194)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L147)

Produces a success result.

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

## 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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs#L155)

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, CommandResultData)

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

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.
