{"record":{"id":"be04224d286f4826","repo":"dotnet/reactive","slug":"rxmainpackage-must-not-be-null","errorCode":null,"errorMessage":"RxMainPackage must not be null.","messagePattern":"RxMainPackage must not be null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Test/Gauntlet/RxGauntlet.Common/CommandLine/RxSourceSettings.cs","lineNumber":100,"sourceCode":"            ..RxUiFrameworkPackagesParsed\n        ];\n\n    /// <summary>\n    /// Validates the command line argument(s).\n    /// </summary>\n    /// <returns>A value indicating whether the settings are valid.</returns>\n    /// <exception cref=\"InvalidOperationException\">\n    /// Thrown if this object's properties are set in a way that we do not expect from Spectre Console CLI.\n    /// </exception>\n    public override ValidationResult Validate()\n    {\n        // Spectre Console will never make the following properties null, so this can only mean that we're being used\n        // in an unsupported way (probably not via Spectre.Console) so we throw instead of reporting a validation\n        // failure.\n\n        if (RxMainPackage is not string rxMainPackage)\n        {\n            throw new InvalidOperationException($\"{nameof(RxMainPackage)} must not be null.\");\n        }\n\n        if (RxUiFrameworkPackages is not string[] rxUiPackages)\n        {\n            throw new InvalidOperationException($\"{nameof(RxUiFrameworkPackages)}  must not be null.\");\n        }\n\n        if (!PackageIdAndVersion.TryParse(rxMainPackage, out _parsedRxMainPackage))\n        {\n            return ValidationResult.Error($\"Invalid package specification: {RxMainPackage}. Must be <PackageId>,<Version>\");\n        }\n\n        if (RxLegacyPackage is string rxLegacyPackage &&\n            !PackageIdAndVersion.TryParse(rxLegacyPackage, out _parsedRxLegacyPackage))\n        {\n            return ValidationResult.Error($\"Invalid package specification: {rxLegacyPackage}. Must be <PackageId>,<Version>\");\n        }\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Test/Gauntlet/RxGauntlet.Common/CommandLine/RxSourceSettings.cs#L82-L118","documentation":"Validate() expects RxMainPackage to be a non-null string; Spectre.Console never supplies null for these options, so null indicates RxSourceSettings is being used outside the supported Spectre.Console path. The method throws InvalidOperationException instead of returning a validation error in that case. It is an API-misuse guard, not a user-input error.","triggerScenarios":"Calling Validate() (directly or via RxPackagesParsed/GetParsedPackage) on an RxSourceSettings instance constructed manually with RxMainPackage left null, i.e. not bound by Spectre.Console's CommandSettings binder.","commonSituations":"Unit tests or scripts instantiating RxSourceSettings with object initializers and forgetting RxMainPackage; custom tooling bypassing the Spectre.Console command layer.","solutions":["Set RxMainPackage to a non-null string in '<PackageId>,<Version>' format before calling Validate()","Instantiate and populate RxSourceSettings through the Spectre.Console command pipeline instead of manually","If you must construct it manually, initialize all required properties: RxMainPackage and RxUiFrameworkPackages"],"exampleFix":"// before\nvar settings = new RxSourceSettings { RxUiFrameworkPackages = new[] { \"Rx.WPF,1.0.0\" } };\nvar result = settings.Validate();\n// after\nvar settings = new RxSourceSettings { RxMainPackage = \"System.Reactive,6.0.1\", RxUiFrameworkPackages = new[] { \"Rx.WPF,1.0.0\" } };\nvar result = settings.Validate();","handlingStrategy":"validation","validationCode":"if (settings.RxMainPackage is null) { throw new ArgumentException(\"RxMainPackage must be set before Validate()\", nameof(settings)); }","typeGuard":"bool usable = settings.RxMainPackage is string s && !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { settings.Validate(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"RxMainPackage must not be null\")) { /* construct via Spectre.Console instead */ }","preventionTips":["Never construct RxSourceSettings manually in production code","Bind settings through Spectre.Console's CommandSettings pipeline","In tests, initialize every required property in the object initializer"],"tags":["csharp","null-argument","api-misuse","spectre-console"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}