{"record":{"id":"2ef3ad072e91700a","repo":"RayWangQvQ/BiliBiliToolPro","slug":"0-1-long-cookie","errorCode":null,"errorMessage":"[{0}]={1} 不能转换为long型，请确认配置的是正确的Cookie值","messagePattern":"\\[(.+?)\\]=(.+?) 不能转换为long型，请确认配置的是正确的Cookie值","errorType":"validation","errorClass":"BiliValidationException","httpStatus":null,"severity":"error","filePath":"src/Ray.BiliBiliTool.Agent/BiliCookie.cs","lineNumber":106,"sourceCode":"                    \"[{0}]={1} 不能转换为long型，请确认配置的是正确的Cookie值\",\n                    GetPropertyDescription(nameof(UserId)),\n                    UserId\n                )\n            );\n        }\n\n        //SessData为空，抛异常\n        if (string.IsNullOrWhiteSpace(SessData))\n        {\n            throw new BiliValidationException(\n                string.Format(msg, GetPropertyDescription(nameof(SessData)))\n            );\n        }\n\n        //BiliJct为空，抛异常\n        if (string.IsNullOrWhiteSpace(BiliJct))\n        {\n            throw new BiliValidationException(\n                string.Format(msg, GetPropertyDescription(nameof(BiliJct)))\n            );\n        }\n\n        if (!result)\n            throw new BiliValidationException(\n                $\"请正确配置Cookie后再运行，配置方式见 {Config.Constants.SourceCodeUrl}\"\n            );\n    }\n\n    private string GetPropertyDescription(string propertyName)\n    {\n        return GetType().GetPropertyDescription(propertyName);\n    }\n}\n","sourceCodeStart":88,"sourceCodeEnd":122,"githubUrl":"https://github.com/RayWangQvQ/BiliBiliToolPro/blob/c599b2c0da964e16ea8c454397aa07bb16212628/src/Ray.BiliBiliTool.Agent/BiliCookie.cs#L88-L122","documentation":"A BiliValidationException thrown from BiliCookie.Check() during cookie validation. The UserId cookie value, read from the configured BiliBili cookie string, failed its long.TryParse conversion — meaning the stored DEDEUserID value is non-numeric, malformed, or empty, so the cookie configuration is invalid and the tool refuses to proceed. This is a validation guard on the user-supplied cookie config: the offending input is the UserId entry of the cookie string (e.g. a truncated, edited, or wrong-field value in place of the numeric DEDEUserID). Check() is exercised by the Check_* test suite (missing/empty dictionary, missing UserId, non-numeric UserId, missing SessData, missing BiliJct).","triggerScenarios":"Cookie string parsed but no bili_jct key/value; tests passing dictionaries without BiliJct.","commonSituations":"Partial cookie copy omitting bili_jct; confusing bili_jct with SESSDATA and providing only one; cookie exported from a logged-out browser session where bili_jct does not exist.","solutions":["Add bili_jct=<value> to the cookie string, copied from browser devtools.","Confirm you copied cookies while logged in to bilibili.","Verify all three required items (DedeUserID, SESSDATA, bili_jct) exist before running."],"exampleFix":"// before\nvar cookie = new BiliCookie(\"DedeUserID=12345; SESSDATA=abc\");\n// after\nvar cookie = new BiliCookie(\"DedeUserID=12345; SESSDATA=abc; bili_jct=6789token\");","handlingStrategy":"validation","validationCode":"if (!cookieString.Contains(\"bili_jct=\"))\n    throw new ArgumentException(\"Cookie 缺少 bili_jct (CSRF token)\");","typeGuard":null,"tryCatchPattern":"try { cookie.Check(); }\ncatch (BiliValidationException ex) { logger.LogError(\"Cookie 缺少 bili_jct: {Msg}\", ex.Message); }","preventionTips":["Copy cookies only while logged in.","Include all three required items: DedeUserID, SESSDATA, bili_jct.","Run Check() before starting scheduled jobs."],"tags":["csharp","cookie","missing-field","csrf"],"backgroundTag":"missing-required-config-field","analyzedSha":"c599b2c0da964e16ea8c454397aa07bb16212628","analyzedAt":"2026-09-12T09:48:04.090Z","contentChangedAt":"2026-09-12T09:48:04.090Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}