{"record":{"id":"dbe90720c24ebe82","repo":"RayWangQvQ/BiliBiliToolPro","slug":"cookie-0","errorCode":null,"errorMessage":"Cookie字符串异常，无[{0}]项","messagePattern":"Cookie字符串异常，无\\[(.+?)\\]项","errorType":"validation","errorClass":"BiliValidationException","httpStatus":null,"severity":"error","filePath":"src/Ray.BiliBiliTool.Agent/BiliCookie.cs","lineNumber":80,"sourceCode":"\n    /// <summary>\n    /// 检查是否已配置\n    /// </summary>\n    /// <returns></returns>\n    public override void Check()\n    {\n        base.Check();\n\n        if (CookieItemDictionary.Count == 0)\n            throw new BiliValidationException(\"Cookie字符串格式异常，内部无等号\");\n\n        bool result = true;\n        string msg = \"Cookie字符串异常，无[{0}]项\";\n\n        //UserId为空，抛异常\n        if (string.IsNullOrWhiteSpace(UserId))\n        {\n            throw new BiliValidationException(\n                string.Format(msg, GetPropertyDescription(nameof(UserId)))\n            );\n        }\n        else if (!long.TryParse(UserId, out long uid)) //不为空，但不能转换为long，警告\n        {\n            throw new BiliValidationException(\n                string.Format(\n                    \"[{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(","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/RayWangQvQ/BiliBiliToolPro/blob/c599b2c0da964e16ea8c454397aa07bb16212628/src/Ray.BiliBiliTool.Agent/BiliCookie.cs#L62-L98","documentation":"During Check, after parsing, the UserId (DedeUserID) item must be present; if it is null/whitespace the library throws BiliValidationException with the formatted message telling which cookie item is missing. It guarantees the cookie identifies the account.","triggerScenarios":"Cookie string parses (has '=') but lacks a DedeUserID entry — e.g. only SESSDATA and bili_jct were copied; tests calling Check with a dictionary missing the UserId key.","commonSituations":"Manually assembled cookie strings omitting DedeUserID; partial cookie copied from a filtered devtools view; sharing a cookie where DedeUserID was removed for privacy.","solutions":["Include the DedeUserID=<your uid> item in the cookie string.","Re-copy the complete cookie from browser devtools rather than hand-building it.","Verify via config that all three required items (DedeUserID, SESSDATA, bili_jct) are present before running."],"exampleFix":"// before\nvar cookie = new BiliCookie(\"SESSDATA=abc; bili_jct=xyz\");\n// after\nvar cookie = new BiliCookie(\"DedeUserID=12345; SESSDATA=abc; bili_jct=xyz\");","handlingStrategy":"validation","validationCode":"var dict = cookieString.Split(';', StringSplitOptions.RemoveEmptyEntries)\n    .Select(p => p.Split('=', 2)).ToDictionary(a => a[0].Trim(), a => a.Length > 1 ? a[1].Trim() : \"\");\nif (!dict.ContainsKey(\"DedeUserID\")) throw new ArgumentException(\"Cookie 缺少 DedeUserID\");","typeGuard":null,"tryCatchPattern":"try { cookie.Check(); }\ncatch (BiliValidationException ex) { logger.LogError(\"Cookie 缺少必需项: {Msg}\", ex.Message); }","preventionTips":["Always export DedeUserID together with SESSDATA and bili_jct.","Never strip items from the cookie 'for privacy' before configuring.","Run Check() before any network call."],"tags":["csharp","cookie","config","missing-field"],"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"}