{"record":{"id":"81610688622ca6a7","repo":"microsoft/aspire","slug":"resource-context-resource-name-binds-volume-volumename-to","errorCode":null,"errorMessage":"Resource '{context.Resource.Name}' binds volume '{VolumeName}' to environment variable '{EnvironmentVariableName}', but compute environment '{environment.Name}' does not support volume mounts. The variable would point at a path that is not backed by storage, so anything written there is lost when the workload restarts. Remove the environment variable binding, or target a compute environment that supports volume mounts.","messagePattern":"Resource '(.+?)' binds volume '(.+?)' to environment variable '(.+?)', but compute environment '(.+?)' does not support volume mounts\\. The variable would point at a path that is not backed by storage, so anything written there is lost when the workload restarts\\. Remove the environment variable binding, or target a compute environment that supports volume mounts\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/VolumeMountBindingAnnotation.cs","lineNumber":143,"sourceCode":"    /// real storage.\n    /// </summary>\n    private void ThrowIfEnvironmentCannotMount(EnvironmentCallbackContext context)\n    {\n        // Only an environment that consumes ContainerMountAnnotation can back the path handed to the\n        // workload. When the environment is known and does not, the variable resolves to ordinary\n        // container storage: writes succeed and are then lost on restart. Fail at publish time instead,\n        // because nothing downstream surfaces the problem.\n        //\n        // A null environment means the model has no compute environment, or several with no explicit\n        // binding. Those are ambiguous rather than known-unsupported, so stay quiet rather than block a\n        // publish that may well be fine.\n        if (context.Resource.GetComputeEnvironment() is not { } environment ||\n            environment is IComputeEnvironmentWithVolumeMounts)\n        {\n            return;\n        }\n\n        throw new InvalidOperationException(\n            $\"Resource '{context.Resource.Name}' binds volume '{VolumeName}' to environment variable \" +\n            $\"'{EnvironmentVariableName}', but compute environment '{environment.Name}' does not support volume \" +\n            $\"mounts. The variable would point at a path that is not backed by storage, so anything written there \" +\n            $\"is lost when the workload restarts. Remove the environment variable binding, or target a compute \" +\n            $\"environment that supports volume mounts.\");\n    }\n\n    private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)\n    {\n        ArgumentException.ThrowIfNullOrEmpty(argument, paramName);\n        return argument;\n    }\n}\n","sourceCodeStart":125,"sourceCodeEnd":157,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/VolumeMountBindingAnnotation.cs#L125-L157","documentation":"ThrowIfEnvironmentCannotMount (invoked from ResolvePath in publish mode) checks the resource's compute environment. If that environment does not implement IComputeEnvironmentWithVolumeMounts, binding a volume to an environment variable would produce a variable pointing at a non-existent/unbacked path, so the library throws InvalidOperationException with a detailed remediation message. This prevents silently persisting data to storage that vanishes on restart.","triggerScenarios":"In publish mode, a resource with a volume mount that is bound to an environment variable (EnvironmentVariableName set) targeting a compute environment (per GetComputeEnvironment()) that lacks volume-mount support — e.g. deploying to a serverless/compute target that has no persistent volume concept.","commonSituations":"Publishing an app with databases/stateful services that use WithDataVolume plus environment-variable bindings to a compute environment that doesn't support mounts; switching deployment targets (e.g. from a VM/container host to a volume-less environment) without removing volume bindings.","solutions":["Remove the environment-variable binding for the volume on this resource, since the target environment can't back it with storage.","Assign the resource to a compute environment that implements IComputeEnvironmentWithVolumeMounts (e.g. a container-apps/VM-style environment that supports volume mounts).","Switch the resource to use managed/external storage appropriate for the target environment (e.g. a cloud database) instead of a local volume.","Adjust the resource's compute environment assignment via WithComputeEnvironment so the mount is supported."],"exampleFix":"// before\nvar cache = builder.AddRedis(\"cache\")\n    .WithDataVolume(\"cache-data\", \"/data\")\n    .WithEnvironment(\"CACHE_DIR\", volumeMount.Path); // publish target can't mount volumes\n\n// after\n// Either drop the env binding, or target a volume-capable compute environment:\nvar cache = builder.AddRedis(\"cache\")\n    .WithDataVolume(\"cache-data\", \"/data\")\n    .WithComputeEnvironment(volumeCapableEnvironment);","handlingStrategy":"validation","validationCode":"// Before publish, verify the target compute environment supports volume mounts:\nvar env = resource.GetComputeEnvironment();\nif (env is not IComputeEnvironmentWithVolumeMounts && resource.HasVolumeMounts())\n    throw new InvalidOperationException($\"Environment '{env?.Name}' cannot back volume mounts for '{resource.Name}'.\");","typeGuard":"static bool SupportsVolumeMounts(IResource resource) =>\n    resource.GetComputeEnvironment() is IComputeEnvironmentWithVolumeMounts or null;","tryCatchPattern":"try\n{\n    await distributedApplication.PublishAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"does not support volume mounts\"))\n{\n    logger.LogError(ex, \"Target compute environment cannot back a volume binding: {Message}\", ex.Message);\n}","preventionTips":["Match resources with volume mounts to compute environments implementing IComputeEnvironmentWithVolumeMounts.","Remove environment-variable bindings to volume paths when targeting volume-less environments.","Prefer managed storage (cloud databases/services) for state when deploying to volume-less compute."],"tags":["volume","compute-environment","publish-mode","storage"],"backgroundTag":"unsupported-operation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}