RayWangQvQ/BiliBiliToolPro · error · BiliValidationException
Cookie字符串异常,无[ ]项
Error message
Cookie字符串异常,无[{0}]项 What it means
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.
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.
Example fix
// before
var cookie = new BiliCookie("SESSDATA=abc; bili_jct=xyz");
// after
var cookie = new BiliCookie("DedeUserID=12345; SESSDATA=abc; bili_jct=xyz"); Defensive patterns
Strategy: validation
Validate before calling
var dict = cookieString.Split(';', StringSplitOptions.RemoveEmptyEntries)
.Select(p => p.Split('=', 2)).ToDictionary(a => a[0].Trim(), a => a.Length > 1 ? a[1].Trim() : "");
if (!dict.ContainsKey("DedeUserID")) throw new ArgumentException("Cookie 缺少 DedeUserID"); Try / catch
try { cookie.Check(); }
catch (BiliValidationException ex) { logger.LogError("Cookie 缺少必需项: {Msg}", ex.Message); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Manually assembled cookie strings omitting DedeUserID; partial cookie copied from a filtered devtools view; sharing a cookie where DedeUserID was removed for privacy.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- Cookie字符串格式异常,内部无等号
- [ ]= 不能转换为long型,请确认配置的是正确的Cookie值
- 请正确配置Cookie后再运行,配置方式见
- Unsupported algorithm
- 登录失败,请检查Cookie
AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12).
Data as JSON: /api/errors/dbe90720c24ebe82.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ray.BiliBiliTool.Agent/BiliCookie.cs:80
/// <summary>
/// 检查是否已配置
/// </summary>
/// <returns></returns>
public override void Check()
{
base.Check();
if (CookieItemDictionary.Count == 0)
throw new BiliValidationException("Cookie字符串格式异常,内部无等号");
bool result = true;
string msg = "Cookie字符串异常,无[{0}]项";
//UserId为空,抛异常
if (string.IsNullOrWhiteSpace(UserId))
{
throw new BiliValidationException(
string.Format(msg, GetPropertyDescription(nameof(UserId)))
);
}
else if (!long.TryParse(UserId, out long uid)) //不为空,但不能转换为long,警告
{
throw new BiliValidationException(
string.Format(
"[{0}]={1} 不能转换为long型,请确认配置的是正确的Cookie值",
GetPropertyDescription(nameof(UserId)),
UserId
)
);
}
//SessData为空,抛异常
if (string.IsNullOrWhiteSpace(SessData))
{
throw new BiliValidationException(View on GitHub (pinned to c599b2c0da)