fullstackhero/dotnet-starter-kit · error · ArgumentOutOfRangeException
Declared size must be positive.
Error message
Declared size must be positive.
What it means
FileAsset.CreatePending validates that declaredSizeBytes > 0 and throws ArgumentOutOfRangeException otherwise. The declared size comes from the client at upload-initiation time and must be a positive number for quota accounting and presigned upload sizing to work.
Solutions
- Reject empty files on the client before calling CreatePending (if size === 0 show a validation error).
- Pass the real byte size from File/Blob.size; never default a missing size to 0.
- If zero-byte uploads must be supported, change the domain rule to allow >= 0 (requires building-block/domain change).
- Check for int/long coercion issues where a large size overflows negative.
Example fix
// before
await startUpload({ fileName: file.name, contentType: file.type, declaredSizeBytes: file.size ?? 0 });
// after
if (!file || file.size <= 0) { showError('File is empty or unreadable.'); return; }
await startUpload({ fileName: file.name, contentType: file.type, declaredSizeBytes: file.size }); Defensive patterns
Strategy: validation
Validate before calling
if (!file || !(file instanceof File) || file.size <= 0) {
showError('File is empty or unreadable.');
return;
} Type guard
const isValidFile = (f: unknown): f is File => f instanceof File && f.size > 0;
Prevention
- Check File.size before initiating any upload
- Disable the submit button for empty selections
- Never default a missing size to 0 — treat it as an error
When it happens
Trigger: Initiating a file upload where declaredSizeBytes is 0 or negative — e.g. a client computing size of an empty file, a missing/null size defaulting to 0, or a signed/rounding bug producing a negative value.
Common situations: Uploading a zero-byte file (empty blob selected); frontend reading file.size after the File object was invalidated; server-side integrations passing a Content-Length of 0 from a failed download.
Related errors
- Actual size must be positive.
- uploaded size ( ) exceeds declared ( )
- uploaded content-type mismatch
- Group DM requires at least 3 distinct members.
- ChannelId is required.
AI-assisted analysis of fullstackhero/dotnet-starter-kit@3f2959e683 (2026-09-15).
Data as JSON: /api/errors/ec598893dbf8eacb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Modules/Files/Modules.Files/Domain/FileAsset.cs:61
Guid? ownerId,
string originalFileName,
string sanitizedFileName,
string contentType,
long declaredSizeBytes,
string storageKey,
Visibility visibility,
string createdByUserId,
DateTimeOffset uploadDeadline)
{
ArgumentException.ThrowIfNullOrWhiteSpace(ownerType);
ArgumentException.ThrowIfNullOrWhiteSpace(originalFileName);
ArgumentException.ThrowIfNullOrWhiteSpace(sanitizedFileName);
ArgumentException.ThrowIfNullOrWhiteSpace(contentType);
ArgumentException.ThrowIfNullOrWhiteSpace(storageKey);
ArgumentException.ThrowIfNullOrWhiteSpace(createdByUserId);
if (declaredSizeBytes <= 0)
{
throw new ArgumentOutOfRangeException(nameof(declaredSizeBytes), "Declared size must be positive.");
}
return new FileAsset
{
Id = id == Guid.Empty ? Guid.CreateVersion7() : id,
OwnerType = ownerType,
OwnerId = ownerId,
OriginalFileName = originalFileName,
FileName = sanitizedFileName,
ContentType = contentType,
SizeBytes = declaredSizeBytes,
StorageKey = storageKey,
Visibility = visibility,
Status = FileAssetStatus.PendingUpload,
ScanStatus = ScanStatus.NotScanned,
UploadDeadline = uploadDeadline,
CreatedByUserId = createdByUserId,
CreatedAtUtc = DateTime.UtcNowView on GitHub (pinned to 3f2959e683)