{"record":{"id":"e3388bdb4f1982b8","repo":"chocolatey/choco","slug":"force-dependencies-can-only-be-used-with-force-als-e3388b","errorCode":null,"errorMessage":"Force dependencies can only be used with force also turned on.","messagePattern":"Force dependencies can only be used with force also turned on\\.","errorType":"validation","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs","lineNumber":284,"sourceCode":"            configuration.Input = string.Join(\" \", unparsedArguments);\r\n            configuration.PackageNames = string.Join(ApplicationParameters.PackageNamesSeparator.ToStringSafe(), unparsedArguments.Where(arg => !arg.StartsWith(\"-\")));\r\n\r\n            if (configuration.RegularOutput)\r\n            {\r\n                WarnForRemovedOptions(unparsedArguments.Where(arg => arg.StartsWith(\"-\")), _removedOptions);\r\n            }\r\n        }\r\n\r\n        public virtual void Validate(ChocolateyConfiguration configuration)\r\n        {\r\n            if (string.IsNullOrWhiteSpace(configuration.PackageNames))\r\n            {\r\n                throw new ApplicationException(\"Package name is required. Please pass at least one package name to upgrade.\");\r\n            }\r\n\r\n            if (configuration.ForceDependencies && !configuration.Force)\r\n            {\r\n                throw new ApplicationException(\"Force dependencies can only be used with force also turned on.\");\r\n            }\r\n\r\n            if (!string.IsNullOrWhiteSpace(configuration.Input))\r\n            {\r\n                var unparsedOptionsAndPackages = configuration.Input.Split(new[] { \" \" }, StringSplitOptions.RemoveEmptyEntries);\r\n                if (!configuration.Information.IsLicensedVersion)\r\n                {\r\n                    foreach (var argument in unparsedOptionsAndPackages.OrEmpty())\r\n                    {\r\n                        var arg = argument.ToLowerSafe();\r\n                        if (arg.StartsWith(\"-dir\") || arg.StartsWith(\"--dir\") || arg.StartsWith(\"-install\") || arg.StartsWith(\"--install\"))\r\n                        {\r\n                            throw new ApplicationException(\"It appears you are attempting to use options that may be only available in licensed versions of Chocolatey ('{0}'). There may be ways in the open source edition to achieve what you are looking to do. Please remove the argument and consult the documentation.\".FormatWith(arg));\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n\r","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs#L266-L302","documentation":"Thrown by ChocolateyUpgradeCommand.Validate() when configuration.ForceDependencies is true but configuration.Force is false. The --force-dependencies option is a strict subset of --force and requires force to also be enabled to prevent accidental destructive dependency operations. This guard ensures the user has explicitly opted into the broader force behavior before touching dependencies.","triggerScenarios":"Running 'choco upgrade <pkg> --force-dependencies' without also passing '--force'. Programmatically setting configuration.ForceDependencies = true without setting configuration.Force = true. The dependency-force flag is parsed and set independently from the force flag, so one can be true while the other is false.","commonSituations":"User misunderstands --force-dependencies as standalone and forgets --force. Script copies a partial flag set between commands. User expects --force-dependencies to imply --force automatically (it does not).","solutions":["Always pass --force together with --force-dependencies: 'choco upgrade <pkg> --force --force-dependencies'","In code, set both: configuration.Force = true; configuration.ForceDependencies = true;","Reconsider whether --force-dependencies is actually needed; it reinstalling all dependencies is rarely necessary"],"exampleFix":"// before\nchoco upgrade mypackage --force-dependencies\n\n// after\nchoco upgrade mypackage --force --force-dependencies","handlingStrategy":"validation","validationCode":"// Validate flag combination before calling the command\nif (configuration.ForceDependencies && !configuration.Force)\n{\n    Console.Error.WriteLine(\"--force-dependencies requires --force to also be enabled.\");\n    return;\n}","typeGuard":"public static bool AreForceFlagsConsistent(ChocolateyConfiguration config)\n{\n    // ForceDependencies being true without Force is invalid\n    return !config.ForceDependencies || config.Force;\n}","tryCatchPattern":"try\n{\n    upgradeCommand.Validate(configuration);\n}\ncatch (ApplicationException ex) when (ex.Message.Contains(\"Force dependencies\"))\n{\n    logger.Error(\"--force-dependencies requires --force. Re-run with both flags.\");\n}","preventionTips":["Always pair --force-dependencies with --force on the command line","When scripting, set both configuration.Force and configuration.ForceDependencies together","Consider whether --force-dependencies is truly necessary, as it reinstalls all dependencies"],"tags":["validation","command-args","upgrade","force","dependencies"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}