diff --git a/src/Aspire.Hosting/Dcp/DcpExecutor.cs b/src/Aspire.Hosting/Dcp/DcpExecutor.cs index 1504bb97060..ed00196e6d2 100644 --- a/src/Aspire.Hosting/Dcp/DcpExecutor.cs +++ b/src/Aspire.Hosting/Dcp/DcpExecutor.cs @@ -14,6 +14,7 @@ using System.Net; using System.Net.Sockets; using System.Runtime.CompilerServices; +using System.Runtime.ExceptionServices; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; @@ -1870,7 +1871,7 @@ private async Task CreateExecutableAsync(RenderedModelResource er, ILogger resou if (configuration.Exception is not null) { - throw new FailedToApplyEnvironmentException(); + ExceptionDispatchInfo.Throw(configuration.Exception); } // Invoke the debug configuration callback now that endpoints are allocated. @@ -2344,7 +2345,11 @@ private async Task CreateContainerAsync(RenderedModelResource cr, ILogger resour spec.Command = containerResource.Entrypoint; } - if (failedToApplyRunArgs || configuration.Exception is not null) + if (configuration.Exception is not null) + { + ExceptionDispatchInfo.Throw(configuration.Exception); + } + if (failedToApplyRunArgs) { throw new FailedToApplyEnvironmentException(); }