{"record":{"id":"17ae5dd49d8e9a77","repo":"beeradmoore/dlss-swapper","slug":"dlss-presets-json-is-empty-or-invalid","errorCode":null,"errorMessage":"dlss_presets.json is empty or invalid.","messagePattern":"dlss_presets\\.json is empty or invalid\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Helpers/NVAPIHelper.cs","lineNumber":124,"sourceCode":"    {\n        // Load DLSS presets\n        try\n        {\n            var dlssPresetsJsonPath = @\"Assets\\dlss_presets.json\";\n            if (File.Exists(dlssPresetsJsonPath) == true)\n            {\n                var dlssPresetOptions = JsonSerializer.Deserialize(File.ReadAllText(dlssPresetsJsonPath), SourceGenerationContext.Default.ListPresetOption)?.Where(x => x.Used == true)?.ToList();\n                if (dlssPresetOptions is not null && dlssPresetOptions.Count > 0)\n                {\n                    for (var i = 0; i < dlssPresetOptions.Count; ++i)\n                    {\n                        dlssPresetOptions[i].UpdateNameFromTranslation();\n                    }\n                    DlssPresetOptions = dlssPresetOptions.AsReadOnly();\n                }\n                else\n                {\n                    throw new Exception(\"dlss_presets.json is empty or invalid.\");\n                }\n            }\n            else\n            {\n                throw new Exception(\"dlss_presets.json not found.\");\n            }\n        }\n        catch (Exception err)\n        {\n            Logger.Error(err, \"Could not load dlss_presets.json, using default presets.\");\n            DlssPresetOptions = [\n                new PresetOption(ResourceHelper.GetString(\"DLSS_Preset_Default\"), 0x00000000),\n                new PresetOption(ResourceHelper.GetFormattedResourceTemplate(\"DLSS_Preset_Letter\", \"A\"), 0x00000001),\n                new PresetOption(ResourceHelper.GetFormattedResourceTemplate(\"DLSS_Preset_Letter\", \"B\"), 0x00000002),\n                new PresetOption(ResourceHelper.GetFormattedResourceTemplate(\"DLSS_Preset_Letter\", \"C\"), 0x00000003),\n                new PresetOption(ResourceHelper.GetFormattedResourceTemplate(\"DLSS_Preset_Letter\", \"D\"), 0x00000004),\n                new PresetOption(ResourceHelper.GetFormattedResourceTemplate(\"DLSS_Preset_Letter\", \"E\"), 0x00000005),\n                new PresetOption(ResourceHelper.GetFormattedResourceTemplate(\"DLSS_Preset_Letter\", \"F\"), 0x00000006),","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/beeradmoore/dlss-swapper/blob/ab9b1e2d4bb04187c48fe58eeea06c2b0ea71fbb/src/Helpers/NVAPIHelper.cs#L106-L142","documentation":"NVAPIHelper throws this when it loads dlss_presets.json to build the DLSS preset option list, but the file's parsed content is empty or fails validation, so no preset options can be constructed. It indicates the embedded/shipped dlss_presets.json resource is missing its expected preset data or has an invalid structure.","triggerScenarios":"Calling the NVAPIHelper initialization that builds DlssPresetOptions when dlss_presets.json exists but deserializes to null/empty or lacks the expected preset entries (the else branch after a successful file read).","commonSituations":"App installed from a broken/partial build where the resource wasn't embedded; the JSON was hand-edited or truncated; a version change renamed or restructured the JSON schema; deployment stripped resource files.","solutions":["Verify dlss_presets.json is present and contains a non-empty, valid presets array (validate with a JSON linter/schema check).","Restore the original dlss_presets.json from a clean install or the repository.","Reinstall/repair the application so the resource is correctly embedded/deployed.","If customizing the file, match the exact schema NVAPIHelper expects before loading."],"exampleFix":"// before (broken file)\n{}\n// after (valid presets file)\n{ \"presets\": [ { \"id\": 1, \"name\": \"Quality\" } ] }","handlingStrategy":"validation","validationCode":"var json = File.ReadAllText(presetPath);\nvar data = JsonSerializer.Deserialize<DlssPresets>(json);\nif (data == null || data.Presets == null || data.Presets.Count == 0)\n    throw new InvalidDataException($\"{presetPath} is empty or has no presets.\");","typeGuard":null,"tryCatchPattern":"try { InitDlssPresets(); }\ncatch (Exception ex) when (ex.Message.Contains(\"dlss_presets.json\"))\n{ Logger.Error(ex); ShowFallbackPresetList(); }","preventionTips":["Validate dlss_presets.json against its schema after any manual edit.","Keep the file deployed/embedded with the app and verify it in install/upgrade scripts.","Back up the original file before customizing presets.","Add a startup integrity check comparing file size/hash to a known-good value."],"tags":["config","json","resource","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"ab9b1e2d4bb04187c48fe58eeea06c2b0ea71fbb","analyzedAt":"2026-09-15T05:25:32.979Z","contentChangedAt":"2026-09-15T05:25:32.979Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}