{"record":{"id":"49120ed00dd0d250","repo":"beeradmoore/dlss-swapper","slug":"failed-to-get-version-count-return-code-returncode","errorCode":null,"errorMessage":"Failed to get version count. Return code: {returnCode}","messagePattern":"Failed to get version count\\. Return code: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Helpers/FSR31/FSR31Helper.cs","lineNumber":73,"sourceCode":"            versionQuery.createDescType = FxxConsts.FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE;\n\n            // versionQuery.device = GetDX12Device(); // only for DirectX 12 applications\n            versionQuery.device = IntPtr.Zero;\n\n            // uint64_t versionCount = 0;\n            UInt64 versionCount = 0;\n            versionQuery.outputCount = Marshal.AllocHGlobal(sizeof(UInt64));\n            Marshal.WriteInt64(versionQuery.outputCount, (UInt32)versionCount);\n\n            Logger.Info(\"AMDFidelityFXAPI - Reading version count\");\n            // get number of versions for allocation\n            // ffxQuery(IntPtr.Zero, &versionQuery.header);\n            var returnCode = ffxQuery(IntPtr.Zero, ref versionQuery);\n            Logger.Info($\"AMDFidelityFXAPI - returnCode: {returnCode}\");\n\n            if (returnCode != FfxApiReturnCodes.FFX_API_RETURN_OK)\n            {\n                throw new Exception($\"Failed to get version count. Return code: {returnCode}\");\n            }\n\n            versionCount = (UInt64)Marshal.ReadInt64(versionQuery.outputCount);\n            Logger.Info($\"AMDFidelityFXAPI - versionCount: {versionCount}\");\n\n            if (versionCount > 0)\n            {\n                var versionCountInt = (int)versionCount;\n\n                //std::vector <const char*> versionNames;\n                //std::vector<uint64_t> versionIds;\n                //m_FsrVersionIds.resize(versionCount);\n                //versionNames.resize(versionCount);\n                var versionNames = new List<string?>(versionCountInt);\n                var versionIds = new List<UInt64>(versionCountInt);\n\n                var versionNamesPtrs = new IntPtr[versionCountInt];\n                var versionIdsPtrs = new IntPtr[versionCountInt];","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/beeradmoore/dlss-swapper/blob/ab9b1e2d4bb04187c48fe58eeea06c2b0ea71fbb/src/Helpers/FSR31/FSR31Helper.cs#L55-L91","documentation":"After obtaining the ffxQuery delegate, GetVersions calls it with a QueryDescGetVersions to first learn how many upscaler versions exist. If the native call returns anything other than FFX_API_RETURN_OK, the helper throws this exception embedding the return code. It means the FidelityFX API rejected the version-count query itself.","triggerScenarios":"ffxQuery(IntPtr.Zero, ref versionQuery) returns a non-OK FfxApiReturnCodes value — e.g. the createDescType is not supported by the loaded backend (FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE unsupported), the descriptor struct layout is wrong for the loaded SDK version, or no FSR backend/context is available.","commonSituations":"Driver or FidelityFX runtime too old to support the upscale query; struct marshaling mismatch after an SDK upgrade changed QueryDescGetVersions layout; calling before any FSR context was ever created on a backend that requires it.","solutions":["Log/decode the returned FfxApiReturnCodes value and look it up in the FFX API headers to identify the exact failure.","Confirm the loaded amd_fidelityfx DLL/driver version supports FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE queries.","Verify QueryDescGetVersions struct layout and field marshaling match the SDK header version in use.","Update GPU drivers and the FidelityFX SDK runtime to matching versions."],"exampleFix":"// before\nvar returnCode = ffxQuery(IntPtr.Zero, ref versionQuery);\nif (returnCode != FfxApiReturnCodes.FFX_API_RETURN_OK) throw new Exception($\"Failed to get version count. Return code: {returnCode}\");\n// after\nvar returnCode = ffxQuery(IntPtr.Zero, ref versionQuery);\nif (returnCode != FfxApiReturnCodes.FFX_API_RETURN_OK)\n    throw new Exception($\"Failed to get version count. Return code: {returnCode} ({DescribeFfxReturnCode(returnCode)}). DLL/driver may not support the upscale query.\");","handlingStrategy":"try-catch","validationCode":"// before calling, confirm the loaded SDK supports the query\nif (!IsFfxUpscaleQuerySupported(loadedSdkVersion))\n    throw new NotSupportedException(\"Loaded FidelityFX runtime does not support the upscale version query.\");","typeGuard":"bool IsOk(FfxApiReturnCodes code) => code == FfxApiReturnCodes.FFX_API_RETURN_OK;","tryCatchPattern":"try\n{\n    GetVersions();\n}\ncatch (Exception ex) when (ex.Message.StartsWith(\"Failed to get version count\"))\n{\n    // decode return code from message, fall back to a default/known version list\n}","preventionTips":["Log the raw FfxApiReturnCodes value on every ffxQuery call for quick diagnosis.","Keep GPU drivers and the FidelityFX SDK updated together.","Validate QueryDescGetVersions marshaling whenever the SDK version changes.","Unit-test the query against a stub native library to catch layout drift."],"tags":["fsr31","native-interop","amd-fidelityfx"],"backgroundTag":"api-error-response","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"}