LykosAI/StabilityMatrix · error · ValidationException
Length cannot be null when latentType is Hunyuan
Error message
Length cannot be null when latentType is Hunyuan
What it means
ComfyNodeBuilderExtensions.SetupEmptyLatentSource builds a ComfyUI latent node for the requested latentType. The Hunyuan branch (EmptyHunyuanLatentVideo) requires a frame Length, which has no default; if the caller supplies null length, the builder throws ValidationException stating that Length is mandatory when latentType is Hunyuan.
Solutions
- Pass an explicit positive length (frame count) when latentType is Hunyuan.
- Add a guard in the calling workflow to require a frame count for Hunyuan before invoking.
- Default length to a sensible value (e.g. 1 or the workflow's frame count) when null for Hunyuan.
Example fix
// before var latent = builder.SetupEmptyLatentSource(latentType, width, height, batchSize, length: null); // after var frames = latentType == LatentType.Hunyuan ? (length ?? 25) : null; var latent = builder.SetupEmptyLatentSource(latentType, width, height, batchSize, length: frames);
Defensive patterns
Strategy: validation
Validate before calling
if (latentType == LatentType.Hunyuan && length is null or <= 0)
throw new InvalidOperationException("Provide a frame length for Hunyuan latents."); Try / catch
try
{
var latent = builder.SetupEmptyLatentSource(latentType, w, h, batch, length);
}
catch (ValidationException ex)
{
notifier.ShowError(ex.Message);
} Prevention
- Always supply a frame count for video latent types like Hunyuan
- Gate Hunyuan workflows behind UI fields that require Length
- Share a single workflow builder that validates latentType-specific requirements
When it happens
Trigger: Calling SetupEmptyLatentSource with latentType = Hunyuan and length = null (or omitting the length argument), e.g. when generating image latents instead of video.
Common situations: Code paths shared between standard image generation (no length needed) and Hunyuan video generation (length required) that forget to set a frame count; UI defaults not wired for Hunyuan workflows.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/87562e7645953ed7.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Avalonia/Extensions/ComfyNodeBuilderExtensions.cs:70
{
Name = builder.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.EmptyFlux2LatentImage)),
BatchSize = batchSize,
Height = height,
Width = width,
}
)
.Output,
LatentType.Hunyuan => builder
.Nodes.AddTypedNode(
new ComfyNodeBuilder.EmptyHunyuanLatentVideo
{
Name = builder.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.EmptyHunyuanLatentVideo)),
BatchSize = batchSize,
Height = height,
Width = width,
Length =
length
?? throw new ValidationException(
"Length cannot be null when latentType is Hunyuan"
),
}
)
.Output,
_ => throw new ArgumentOutOfRangeException(nameof(latentType), latentType, null),
};
builder.Connections.Primary = primaryNodeConnection;
builder.Connections.PrimarySize = new Size(width, height);
// If batch index is selected, add a LatentFromBatch
if (batchIndex is not null)
{
builder.Connections.Primary = builder
.Nodes.AddTypedNode(
new ComfyNodeBuilder.LatentFromBatch
{View on GitHub (pinned to af93d6ef57)