{"record":{"id":"b55b8fc6828726d5","repo":"OdysseusYuan/LKY_OfficeTools","slug":"sdk","errorCode":null,"errorMessage":"读取 SDK 内存资源失败！","messagePattern":"读取 SDK 内存资源失败！","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"LKY_OfficeTools/Lib/Lib_AppSdk.cs","lineNumber":105,"sourceCode":"                }\n            }\n        }\n\n        internal static bool Initial()\n        {\n            try\n            {\n                new Log($\"\\n------> 正在配置 {AppAttribute.AppName} 基础组件 ...\", ConsoleColor.DarkCyan);\n                Thread.Sleep(1000);      //短暂间隔，提升下体验\n                new Log($\"     >> 此过程会持续些许时间，这取决于您的电脑硬件配置，请耐心等待 ...\", ConsoleColor.DarkYellow);\n\n                //初始化前先清理SDK目录，防止因为文件已经存在，引发解压的catch\n                Clean();\n\n                //释放文件\n                if (SdkPackageDic == null)\n                {\n                    throw new Exception(\"读取 SDK 内存资源失败！\");\n                }\n                foreach (var now_pkg in SdkPackageDic)\n                {\n                    string pkg_path = SdkPkgPath[now_pkg.Key];\n                    bool isToDisk = Com_FileOS.Write.FromStream(now_pkg.Value, pkg_path);\n                    if (!isToDisk)\n                    {\n                        //写出异常，抛出\n                        throw new IOException($\"无法写出 SDK 文件 {pkg_path} 到硬盘！\");\n                    }\n\n                    //无异常，解压包\n                    ZipFile.ExtractToDirectory(pkg_path, Documents.SDKs.SDKs_Root + $@\"\\{now_pkg.Key}\");\n                }\n\n                new Log($\"     √ 已完成 {AppAttribute.AppName} 组件配置。\", ConsoleColor.DarkGreen);\n\n                return true;","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/OdysseusYuan/LKY_OfficeTools/blob/6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf/LKY_OfficeTools/Lib/Lib_AppSdk.cs#L87-L123","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Call Assembly.GetExecutingAssembly().GetManifestResourceNames() and confirm each `<root>.Resource.SDK.<Pkg>.lotp` name is present.","Set Build Action = Embedded Resource on every .lotp file in Resource/SDK/.","Keep AppDevelop.NameSpace_Top in sync with the project's Default Namespace.","Rebuild cleanly after fixing resource metadata; verify the assembly actually grew by the resource size."],"exampleFix":"// before (resource not found because namespace drifted)\n// Lib_AppSdk relies on AppDevelop.NameSpace_Top matching the default namespace.\n\n// after\n// In the project, set each Resource/SDK/*.lotp Build Action = 'Embedded Resource',\n// then ensure:\ninternal static class AppDevelop { internal const string NameSpace_Top = \"LKY_OfficeTools\"; }\n// and verify at runtime:\nforeach (var n in Assembly.GetExecutingAssembly().GetManifestResourceNames())\n    Console.WriteLine(n);","handlingStrategy":"validation","validationCode":"var names = Assembly.GetExecutingAssembly().GetManifestResourceNames();\nstring want = AppDevelop.NameSpace_Top + \".Resource.SDK.Activate.lotp\";\nif (!names.Contains(want)) { /* fix Build Action / NameSpace_Top before Initial */ return; }","typeGuard":"static bool SdkResourcesPresent()\n{\n    var have = new HashSet<string>(Assembly.GetExecutingAssembly().GetManifestResourceNames());\n    return have.Contains(AppDevelop.NameSpace_Top + \".Resource.SDK.Activate.lotp\")\n        && have.Contains(AppDevelop.NameSpace_Top + \".Resource.SDK.Aria2c.lotp\")\n        && have.Contains(AppDevelop.NameSpace_Top + \".Resource.SDK.ODT.lotp\")\n        && have.Contains(AppDevelop.NameSpace_Top + \".Resource.SDK.SaRA.lotp\");\n}","tryCatchPattern":null,"preventionTips":["Set Build Action = Embedded Resource on every Resource/SDK/*.lotp file.","Keep AppDevelop.NameSpace_Top in sync with the project Default Namespace.","After a rename/refactor, enumerate GetManifestResourceNames() to verify identity.","Initial calls Quit(-10) on this path, so prevent it at build time rather than runtime."],"tags":["embedded-resource","manifest","reflection","sdk","build-config"],"backgroundTag":null,"analyzedSha":"6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf","analyzedAt":"2026-08-13T18:00:34.810Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}