OdysseusYuan/LKY_OfficeTools · critical · IOException

无法写出 SDK 文件 {pkg_path} 到硬盘!

Error message

无法写出 SDK 文件 {pkg_path} 到硬盘!

What it means

Thrown in Lib_AppSdk.Initial when Com_FileOS.Write.FromStream returns false for a given pkg_path (Lib_AppSdk.cs:110-114), wrapped as IOException. FromStream returning false means writing the embedded SDK package to disk failed. Initial's IOException catch logs it, tells the user to ensure enough writable space on the system drive, cleans the SDK dir, and calls KeyMsg.Quit(-2) (Lib_AppSdk.cs:125-141).

Source

Thrown at LKY_OfficeTools/Lib/Lib_AppSdk.cs:114

                Thread.Sleep(1000);      //短暂间隔,提升下体验
                new Log($"     >> 此过程会持续些许时间,这取决于您的电脑硬件配置,请耐心等待 ...", ConsoleColor.DarkYellow);

                //初始化前先清理SDK目录,防止因为文件已经存在,引发解压的catch
                Clean();

                //释放文件
                if (SdkPackageDic == null)
                {
                    throw new Exception("读取 SDK 内存资源失败!");
                }
                foreach (var now_pkg in SdkPackageDic)
                {
                    string pkg_path = SdkPkgPath[now_pkg.Key];
                    bool isToDisk = Com_FileOS.Write.FromStream(now_pkg.Value, pkg_path);
                    if (!isToDisk)
                    {
                        //写出异常,抛出
                        throw new IOException($"无法写出 SDK 文件 {pkg_path} 到硬盘!");
                    }

                    //无异常,解压包
                    ZipFile.ExtractToDirectory(pkg_path, Documents.SDKs.SDKs_Root + $@"\{now_pkg.Key}");
                }

                new Log($"     √ 已完成 {AppAttribute.AppName} 组件配置。", ConsoleColor.DarkGreen);

                return true;
            }
            catch (IOException IO_Ex)
            {
                new Log(IO_Ex.ToString());

                //读写出现意外
                new Log($"     × 配置 {AppAttribute.AppName} 基础组件失败。请确保您的系统盘具备足够的可写空间!", ConsoleColor.DarkRed);

                //清理SDK缓存

View on GitHub (pinned to 6f9a1bd471)

Solutions

  1. Free space on the system drive and confirm Documents.SDKs.SDKs_Root is writable before calling Initial.
  2. Shorten the SDK target path or enable long-path support to avoid the 260-char limit.
  3. Temporarily disable/exclude the SDK folder in antivirus to rule out lock/quarantine.
  4. Run the host process under an account with write permission to the Documents folder.

Example fix

// before
Lib_AppSdk.Initial();

// after
string root = Documents.SDKs.SDKs_Root;
Directory.CreateDirectory(root);
if (new DriveInfo(Path.GetPathRoot(root)).AvailableFreeSpace < 50L * 1024 * 1024)
{ /* not enough space; abort before Initial */ return; }
Lib_AppSdk.Initial();
Defensive patterns

Strategy: validation

Validate before calling

string root = Documents.SDKs.SDKs_Root;
Directory.CreateDirectory(root);
long free = new DriveInfo(Path.GetPathRoot(root)).AvailableFreeSpace;
if (free < 50L * 1024 * 1024) { /* not enough space; abort before Initial */ return; }
Lib_AppSdk.Initial();

Type guard

static bool WritableWithSpace(string dir, long minBytes)
{
    try
    {
        Directory.CreateDirectory(dir);
        string probe = Path.Combine(dir, $".wprobe_{Guid.NewGuid():N}");
        File.WriteAllText(probe, "");
        File.Delete(probe);
        return new DriveInfo(Path.GetPathRoot(dir)).AvailableFreeSpace >= minBytes;
    }
    catch { return false; }
}

Prevention

When it happens

Trigger: The system drive (where Documents.SDKs.SDKs_Root lives) is full; the path is too long (>260 chars); a file lock or antivirus blocks the write; or the target directory cannot be created. FromStream returns false for any of these write failures.

Common situations: Low-disk-space VMs used for testing; path-length limits on deeply nested user profiles; AV scanning/quarantining freshly written .lotp files; read-only Documents folder under a restricted account.

Related errors


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