{"record":{"id":"9ecb0447702cc46c","repo":"LykosAI/StabilityMatrix","slug":"sampler-not-selected-wansamplercardviewmodel","errorCode":null,"errorMessage":"Sampler not selected","messagePattern":"Sampler not selected","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/ViewModels/Inference/WanSamplerCardViewModel.cs","lineNumber":48,"sourceCode":"        EnableAddons = false;\n        IsLengthEnabled = true;\n        SelectedSampler = ComfySampler.UniPC;\n        SelectedScheduler = ComfyScheduler.Simple;\n        Length = 33;\n    }\n\n    public override void ApplyStep(ModuleApplyStepEventArgs e)\n    {\n        if (EnableAddons)\n        {\n            foreach (var module in ModulesCardViewModel.Cards.OfType<ModuleBase>())\n            {\n                module.ApplyStep(e);\n            }\n        }\n\n        // Set primary sampler and scheduler\n        var primarySampler = SelectedSampler ?? throw new ValidationException(\"Sampler not selected\");\n        e.Builder.Connections.PrimarySampler = primarySampler;\n\n        var primaryScheduler = SelectedScheduler ?? throw new ValidationException(\"Scheduler not selected\");\n        e.Builder.Connections.PrimaryScheduler = primaryScheduler;\n\n        // for later inheritance if needed\n        e.Builder.Connections.PrimaryCfg = CfgScale;\n        e.Builder.Connections.PrimarySteps = Steps;\n        e.Builder.Connections.PrimaryModelType = SelectedModelType;\n\n        e.Temp = e.CreateTempFromBuilder();\n\n        var conditioning = e.Temp.Base.Conditioning.Unwrap();\n\n        var isImgToVid = IsDenoiseStrengthEnabled;\n\n        if (isImgToVid)\n        {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/ViewModels/Inference/WanSamplerCardViewModel.cs#L30-L66","documentation":"In Stability Matrix's ComfyUI inference workflow builder, WanSamplerCardViewModel.ApplyStep() reads the user-selected sampler from SelectedSampler and assigns it as the workflow's PrimarySampler. The property is nullable (ComfySampler?), so when nothing is selected the code throws a System.ComponentModel.DataAnnotations.ValidationException to abort workflow generation with a clear message instead of emitting a malformed ComfyUI graph.","triggerScenarios":"Running a Wan image/video generation when WanSamplerCardViewModel.SelectedSampler is null at ApplyStep time — e.g. the sampler picker was never populated (ComfyUI client not connected / sampler list not loaded) or the bound selection was reset before the Generate button invoked the module pipeline.","commonSituations":"ComfyUI backend disconnected so available samplers never load into the dropdown; a saved prompt/layout was restored with a sampler value that no longer exists, leaving the selection null; a developer constructed WanSamplerCardViewModel manually (or via DI) and called ApplyStep without setting SelectedSampler; UI binding failure between the SamplerCard view and the view model.","solutions":["Connect to a ComfyUI instance (check the Inference tab connection status) so the sampler list loads, then pick a sampler in the Wan sampler card dropdown before generating.","Reopen the Inference tab or restart Stability Matrix so the sampler card re-initializes — the constructor defaults SelectedSampler to ComfySampler.UniPC.","If constructing the card in code/tests, explicitly set SelectedSampler (e.g. card.SelectedSampler = ComfySampler.UniPC) before calling ApplyStep.","Check that the sampler dropdown's ItemsSource binding is populated (ComfySamplers from IInferenceClientManager) if the null selection persists."],"exampleFix":"// before (throws)\nvar primarySampler = SelectedSampler ?? throw new ValidationException(\"Sampler not selected\");\n// after (defensive default)\nvar primarySampler = SelectedSampler ?? ComfySampler.UniPC;","handlingStrategy":"validation","validationCode":"if (card.SelectedSampler is null)\n    throw new ValidationException(\"Select a sampler before generating.\");\ncard.ApplyStep(e);","typeGuard":"bool HasSampler(WanSamplerCardViewModel c) => c.SelectedSampler is not null;","tryCatchPattern":"try { card.ApplyStep(e); }\ncatch (ValidationException ex) { NotifyUser(ex.Message); }","preventionTips":["Rely on the constructor default (SelectedSampler = ComfySampler.UniPC); never null it out.","Ensure the ComfyUI connection is established before showing the Inference tab so sampler lists load.","Add a UI-level validation check on Generate that surfaces unselected sampler/scheduler cards before ApplyStep runs.","In tests, construct the card with defaults rather than clearing selections."],"tags":["csharp","avalonia","inference","validation","comfyui"],"backgroundTag":"missing-required-argument","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}