{"record":{"id":"a42fb88608f46aad","repo":"JeffreySu/WeiXinMPSDK","slug":"finance-windows-linux","errorCode":null,"errorMessage":"企业微信 Finance 会话内容存档原生库仅支持 Windows 和 Linux。","messagePattern":"企业微信 Finance 会话内容存档原生库仅支持 Windows 和 Linux。","errorType":"exception","errorClass":"PlatformNotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceNativeApi.cs","lineNumber":361,"sourceCode":"        /// <param name=\"path\">动态库路径或文件名。</param>\n        /// <returns>已经加载的动态库句柄。</returns>\n        public static FinanceLibraryHandle Load(string path)\n        {\n            if (FinanceRuntimePlatform.IsWindows)\n            {\n                var handle = WindowsNative.LoadLibrary(path);\n                if (handle == IntPtr.Zero)\n                {\n                    throw new Win32Exception(Marshal.GetLastWin32Error(),\n                        $\"无法加载企业微信 Finance 原生库：{path}\");\n                }\n\n                return new FinanceLibraryHandle(handle, true, false);\n            }\n\n            if (!FinanceRuntimePlatform.IsLinux)\n            {\n                throw new PlatformNotSupportedException(\n                    \"企业微信 Finance 会话内容存档原生库仅支持 Windows 和 Linux。\");\n            }\n\n            IntPtr linuxHandle;\n            var useLegacy = false;\n            try\n            {\n                linuxHandle = LinuxNative.DlOpen(path, RtldNow);\n            }\n            catch (DllNotFoundException)\n            {\n                useLegacy = true;\n                linuxHandle = LinuxLegacyNative.DlOpen(path, RtldNow);\n            }\n\n            if (linuxHandle == IntPtr.Zero)\n            {\n                var detail = useLegacy ? LinuxLegacyNative.GetError() : LinuxNative.GetError();","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceNativeApi.cs#L343-L379","documentation":"The WeChat Work Finance session-archive SDK only ships native binaries for Windows and Linux. When FinanceLibraryHandle.Load runs on any other OS (e.g. macOS), it throws PlatformNotSupportedException immediately — before any network call is attempted.","triggerScenarios":"Calling the MsgAudit Finance API from an app running on macOS (local dev on a Mac) or any platform that is neither Windows nor Linux.","commonSituations":"Developing/testing message-archiving code on a MacBook; hosting the service on an unsupported platform; unit tests running on macOS CI agents.","solutions":["Run the service on Windows or Linux (the only platforms with an official Finance SDK).","For local dev on macOS, point the code at a Linux container or a remote Windows/Linux test environment.","Skip/condition finance-related tests so they only execute on supported OSes (e.g. [SkippableFact] with OS check).","If you control the runtime image, use a linux-x64 Docker base image and ship the .so SDK."],"exampleFix":"// before\nvar api = MsgAuditFinanceNativeApi.Create(); // throws on macOS\n// after\nif (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !RuntimeInformation.IsOSPlatform(OSPlatform.Linux))\n{\n    throw new SkipTestException(\"Finance SDK requires Windows or Linux\");\n}\nvar api = MsgAuditFinanceNativeApi.Create();","handlingStrategy":"validation","validationCode":"bool supported = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux);\nif (!supported) throw new PlatformNotSupportedException(\"Finance SDK requires Windows or Linux\");","typeGuard":"static bool IsFinanceSupported() =>\n    RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux);","tryCatchPattern":"try { var api = MsgAuditFinanceNativeApi.Create(); }\ncatch (PlatformNotSupportedException) { logger.LogWarning(\"Finance archiving disabled on this OS\"); return null; }","preventionTips":["Check OS at startup and disable message-archiving features gracefully.","Run integration tests for finance only on Windows/Linux agents.","Use linux-x64 Docker images for deployments."],"tags":["platform","native-library","unsupported-os"],"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"}