{"record":{"id":"ec598893dbf8eacb","repo":"fullstackhero/dotnet-starter-kit","slug":"declared-size-must-be-positive","errorCode":null,"errorMessage":"Declared size must be positive.","messagePattern":"Declared size must be positive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Modules/Files/Modules.Files/Domain/FileAsset.cs","lineNumber":61,"sourceCode":"        Guid? ownerId,\n        string originalFileName,\n        string sanitizedFileName,\n        string contentType,\n        long declaredSizeBytes,\n        string storageKey,\n        Visibility visibility,\n        string createdByUserId,\n        DateTimeOffset uploadDeadline)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(ownerType);\n        ArgumentException.ThrowIfNullOrWhiteSpace(originalFileName);\n        ArgumentException.ThrowIfNullOrWhiteSpace(sanitizedFileName);\n        ArgumentException.ThrowIfNullOrWhiteSpace(contentType);\n        ArgumentException.ThrowIfNullOrWhiteSpace(storageKey);\n        ArgumentException.ThrowIfNullOrWhiteSpace(createdByUserId);\n        if (declaredSizeBytes <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(declaredSizeBytes), \"Declared size must be positive.\");\n        }\n\n        return new FileAsset\n        {\n            Id = id == Guid.Empty ? Guid.CreateVersion7() : id,\n            OwnerType = ownerType,\n            OwnerId = ownerId,\n            OriginalFileName = originalFileName,\n            FileName = sanitizedFileName,\n            ContentType = contentType,\n            SizeBytes = declaredSizeBytes,\n            StorageKey = storageKey,\n            Visibility = visibility,\n            Status = FileAssetStatus.PendingUpload,\n            ScanStatus = ScanStatus.NotScanned,\n            UploadDeadline = uploadDeadline,\n            CreatedByUserId = createdByUserId,\n            CreatedAtUtc = DateTime.UtcNow","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/fullstackhero/dotnet-starter-kit/blob/3f2959e683e9f83f13e55e1678c9119f63c7e8e5/src/Modules/Files/Modules.Files/Domain/FileAsset.cs#L43-L79","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait startUpload({ fileName: file.name, contentType: file.type, declaredSizeBytes: file.size ?? 0 });\n// after\nif (!file || file.size <= 0) { showError('File is empty or unreadable.'); return; }\nawait startUpload({ fileName: file.name, contentType: file.type, declaredSizeBytes: file.size });","handlingStrategy":"validation","validationCode":"if (!file || !(file instanceof File) || file.size <= 0) {\n  showError('File is empty or unreadable.');\n  return;\n}","typeGuard":"const isValidFile = (f: unknown): f is File => f instanceof File && f.size > 0;","tryCatchPattern":null,"preventionTips":["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"],"tags":["files","upload","argument","validation"],"backgroundTag":"argument-out-of-range","analyzedSha":"3f2959e683e9f83f13e55e1678c9119f63c7e8e5","analyzedAt":"2026-09-15T22:20:53.684Z","contentChangedAt":"2026-09-15T22:20:53.684Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}