OdysseusYuan/LKY_OfficeTools · error · Exception

Office 信息获取失败!

Error message

Office 信息获取失败!

What it means

Thrown after iterating every URL in the OfficeChannels_Url list and getting null/empty from Com_WebOS.Visit_WebClient for each one. Visit_WebClient returns null on any network or HTTP error (DNS failure, connection refused, timeout, 404/500, TLS handshake failure, proxy rejection). This error therefore means all configured Office channel mirrors are unreachable simultaneously.

Source

Thrown at LKY_OfficeTools/Lib/Lib_OfficeInfo.cs:92

                            office_info = Com_WebOS.Visit_WebClient(now_url.Replace(" ", ""));      //替换网址空格,并获得当前网址的访问信息
                            if (!string.IsNullOrEmpty(office_info))
                            {
                                new Log($"     √ 已获得 Office 最新正版信息。", ConsoleColor.DarkGreen);

                                //info有值,返回该值。
                                return _office_channel_info = office_info;
                            }

                            //访问当前网址返回数据为空,或者无法截取获得有效字段时,遍历。
                            if (try_times < channel_list.Count)
                            {
                                new Log($"     >> 尝试使用 {++try_times} 号服务器获取中 ...", ConsoleColor.DarkYellow);
                                continue;
                            }
                        }

                        //全部遍历完,依旧没返回,就说明全部失败
                        throw new Exception("Office 信息获取失败!");
                    }
                    catch (Exception Ex)
                    {
                        new Log("     × 最新 Office 信息获取失败,请稍后重试!", ConsoleColor.DarkRed);
                        new Log(Ex.ToString());
                        return null;
                    }
                }
            }

            private static Version _office_latest_version;
            internal static Version OfficeLatestVersion
            {
                get
                {
                    try
                    {
                        //非空返回

View on GitHub (pinned to 6f9a1bd471)

Solutions

  1. Confirm overall internet connectivity (e.g. ping a stable host).
  2. Test each channel URL directly in a browser or with curl to see which return content.
  3. If behind a proxy/firewall, whitelist the Office CDN/mirror domains.
  4. Retry after a short wait — transient mirror outages resolve on their own.
  5. Verify the URLs in OfficeChannels_Url are current and not pointing at decommissioned hosts.

Example fix

// before
foreach (var now_url in channel_list)
{
    office_info = Com_WebOS.Visit_WebClient(now_url.Replace(" ", ""));
    if (!string.IsNullOrEmpty(office_info))
        return _office_channel_info = office_info;
    if (try_times < channel_list.Count) { new Log($">> 尝试 {++try_times} 号服务器..."); continue; }
}
throw new Exception("Office 信息获取失败!");

// after — add a bounded retry-with-backoff before giving up
for (int attempt = 0; attempt < 3; attempt++)
{
    foreach (var now_url in channel_list)
    {
        office_info = Com_WebOS.Visit_WebClient(now_url.Replace(" ", ""));
        if (!string.IsNullOrEmpty(office_info))
            return _office_channel_info = office_info;
    }
    if (attempt < 2) System.Threading.Thread.Sleep(3000 * (attempt + 1));
}
throw new Exception("Office 信息获取失败!所有镜像均不可达,请检查网络。");
Defensive patterns

Strategy: retry

Validate before calling

// Optional pre-flight: confirm at least one channel URL is reachable before iterating.
// (Visit_WebClient has no separate ping, so this is effectively the same call — keep the retry loop instead.)
null

Try / catch

// Retry the full mirror list a few times with backoff before surfacing the error.
string office_info = null;
for (int attempt = 0; attempt < 3 && office_info == null; attempt++)
{
    foreach (var now_url in channel_list)
    {
        office_info = Com_WebOS.Visit_WebClient(now_url.Replace(" ", ""));
        if (!string.IsNullOrEmpty(office_info)) break;
    }
    if (office_info == null && attempt < 2) System.Threading.Thread.Sleep(3000 * (attempt + 1));
}
if (office_info == null)
    throw new Exception("所有 Office 镜像均不可达,请检查网络后重试。");

Prevention

When it happens

Trigger: Every URL in the semicolon-separated channel_list returns null from Visit_WebClient — e.g. total network outage, all mirror hosts down, all URLs stale/misconfigured, a proxy blocking all CDN domains, or TLS/DNS failure affecting all targets.

Common situations: Complete network outage; corporate firewall blocking all Microsoft CDN / Office update domains; all mirror URLs in the config are stale and return 404; DNS resolution failing system-wide; a captive portal intercepting all requests.

Related errors


AI-assisted analysis of OdysseusYuan/LKY_OfficeTools@6f9a1bd471 (2026-08-13). Data as JSON: /api/errors/6c1d1f8a2aaf16ab. Report an issue: GitHub.