OdysseusYuan/LKY_OfficeTools · critical · Exception

读取 SDK 内存资源失败!

Error message

读取 SDK 内存资源失败!

What it means

Thrown in Lib_AppSdk.Initial when the SdkPackageDic property is null (Lib_AppSdk.cs:103-105). That property builds a Dictionary from Assembly.GetExecutingAssembly().GetManifestResourceStream(...) for each SDK package; it returns null from its catch when a resource stream is null (resource name not found) or when reflection throws. The interpolated name is fixed text because resource identity is compile-time. Initial's generic catch logs it, cleans the SDK dir, and calls KeyMsg.Quit(-10) (Lib_AppSdk.cs:159-175).

Source

Thrown at LKY_OfficeTools/Lib/Lib_AppSdk.cs:105

                }
            }
        }

        internal static bool Initial()
        {
            try
            {
                new Log($"\n------> 正在配置 {AppAttribute.AppName} 基础组件 ...", ConsoleColor.DarkCyan);
                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;

View on GitHub (pinned to 6f9a1bd471)

Solutions

  1. Call Assembly.GetExecutingAssembly().GetManifestResourceNames() and confirm each `<root>.Resource.SDK.<Pkg>.lotp` name is present.
  2. Set Build Action = Embedded Resource on every .lotp file in Resource/SDK/.
  3. Keep AppDevelop.NameSpace_Top in sync with the project's Default Namespace.
  4. Rebuild cleanly after fixing resource metadata; verify the assembly actually grew by the resource size.

Example fix

// before (resource not found because namespace drifted)
// Lib_AppSdk relies on AppDevelop.NameSpace_Top matching the default namespace.

// after
// In the project, set each Resource/SDK/*.lotp Build Action = 'Embedded Resource',
// then ensure:
internal static class AppDevelop { internal const string NameSpace_Top = "LKY_OfficeTools"; }
// and verify at runtime:
foreach (var n in Assembly.GetExecutingAssembly().GetManifestResourceNames())
    Console.WriteLine(n);
Defensive patterns

Strategy: validation

Validate before calling

var names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
string want = AppDevelop.NameSpace_Top + ".Resource.SDK.Activate.lotp";
if (!names.Contains(want)) { /* fix Build Action / NameSpace_Top before Initial */ return; }

Type guard

static bool SdkResourcesPresent()
{
    var have = new HashSet<string>(Assembly.GetExecutingAssembly().GetManifestResourceNames());
    return have.Contains(AppDevelop.NameSpace_Top + ".Resource.SDK.Activate.lotp")
        && have.Contains(AppDevelop.NameSpace_Top + ".Resource.SDK.Aria2c.lotp")
        && have.Contains(AppDevelop.NameSpace_Top + ".Resource.SDK.ODT.lotp")
        && have.Contains(AppDevelop.NameSpace_Top + ".Resource.SDK.SaRA.lotp");
}

Prevention

When it happens

Trigger: A GetManifestResourceStream call returns null because the embedded resource name does not exactly match `<AppDevelop.NameSpace_Top>.Resource.SDK.<Pkg>.lotp`. This happens when the default namespace was renamed but NameSpace_Top was not updated, or when the .lotp files do not have Build Action = Embedded Resource.

Common situations: Repo/folder rename that changed the default namespace without updating AppDevelop.NameSpace_Top; resource files excluded or set to 'None'/'Content' instead of 'Embedded Resource'; IL trimming/obfuscation stripping embedded resources; wrong configuration built.

Related errors


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