{"record":{"id":"3d10cc8fe586f790","repo":"JeffreySu/WeiXinMPSDK","slug":"finance-windows-linux-librarypath","errorCode":null,"errorMessage":"企业微信官方未提供当前操作系统可用的 Finance 会话内容存档原生库。请在 Windows 或 Linux 上运行，并在 LibraryPath 中指定对应的官方库。","messagePattern":"企业微信官方未提供当前操作系统可用的 Finance 会话内容存档原生库。请在 Windows 或 Linux 上运行，并在 LibraryPath 中指定对应的官方库。","errorType":"exception","errorClass":"PlatformNotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceNativeApi.cs","lineNumber":235,"sourceCode":"            }\n\n            _disposed = true;\n            _library.Dispose();\n        }\n\n        private static string GetDefaultLibraryName()\n        {\n            if (FinanceRuntimePlatform.IsWindows)\n            {\n                return WindowsLibraryName;\n            }\n\n            if (FinanceRuntimePlatform.IsLinux)\n            {\n                return LinuxLibraryName;\n            }\n\n            throw new PlatformNotSupportedException(\n                \"企业微信官方未提供当前操作系统可用的 Finance 会话内容存档原生库。\" +\n                \"请在 Windows 或 Linux 上运行，并在 LibraryPath 中指定对应的官方库。\");\n        }\n\n        private static string ReadUtf8(IntPtr pointer, int length, string bufferName)\n        {\n            var bytes = ReadBytes(pointer, length, bufferName);\n            return bytes.Length == 0 ? string.Empty : Encoding.UTF8.GetString(bytes);\n        }\n\n        private static byte[] ReadBytes(IntPtr pointer, int length, string bufferName)\n        {\n            if (length < 0)\n            {\n                throw new InvalidOperationException($\"Finance SDK 返回了无效的 {bufferName} 长度：{length}。\");\n            }\n\n            if (length == 0)","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceNativeApi.cs#L217-L253","documentation":"MsgAuditFinanceNativeApi.GetDefaultLibraryName maps the current OS to the official native library (Windows DLL or Linux .so). On any other OS (macOS, BSD, etc.) the official WeWork Finance SDK provides no library, so the code throws PlatformNotSupportedException advising Windows/Linux or an explicit LibraryPath.","triggerScenarios":"Constructing MsgAuditFinanceClient on macOS or another unsupported OS without setting MsgAuditFinanceOptions.LibraryPath, so the default library name resolution fails.","commonSituations":"Developing on a Mac and deploying without specifying LibraryPath, CI mac runners running integration tests, or containers on unusual platforms lacking the native lib.","solutions":["Run on Windows or Linux where the official native library is available","Set MsgAuditFinanceOptions.LibraryPath explicitly to a library your platform can load (if you have a compatible build)","Build/publish for a linux-x64 or win-x64 runtime identifier in deployment/CI","Use a Linux container or VM for local development on macOS"],"exampleFix":"// before\nvar options = new MsgAuditFinanceOptions { CorpId = corpId, Secret = secret }; // macOS: no default lib\n// after\nvar options = new MsgAuditFinanceOptions { CorpId = corpId, Secret = secret, LibraryPath = \"/opt/wework/libWeWorkFinanceSdk_C.so\" }; // or run on Linux","handlingStrategy":"fallback","validationCode":"if (!OperatingSystem.IsWindows() && !OperatingSystem.IsLinux() && string.IsNullOrWhiteSpace(options.LibraryPath))\n    throw new PlatformNotSupportedException(\"Set LibraryPath explicitly or run on Windows/Linux\");","typeGuard":"bool CanLoadDefaultLibrary() => OperatingSystem.IsWindows() || OperatingSystem.IsLinux();","tryCatchPattern":"try { var client = new MsgAuditFinanceClient(options); }\ncatch (PlatformNotSupportedException ex) when (ex.Message.Contains(\"Finance\")) { /* switch host/container to linux-x64 or configure LibraryPath */ }","preventionTips":["Publish with linux-x64/win-x64 runtime identifiers for deployment","On macOS dev machines, run the SDK-dependent code in a Linux container","Set LibraryPath explicitly when the default resolution cannot be relied on","Verify architecture match between the native lib and the process in CI"],"tags":["csharp","platform","native-library","macos","weixin-work"],"backgroundTag":"unsupported-platform","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}