JeffreySu/WeiXinMPSDK · error · PlatformNotSupportedException

企业微信官方未提供当前操作系统可用的 Finance 会话内容存档原生库。请在 Windows 或 Linux…

Error message

企业微信官方未提供当前操作系统可用的 Finance 会话内容存档原生库。请在 Windows 或 Linux 上运行,并在 LibraryPath 中指定对应的官方库。

What it means

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.

Solutions

  1. Run on Windows or Linux where the official native library is available
  2. Set MsgAuditFinanceOptions.LibraryPath explicitly to a library your platform can load (if you have a compatible build)
  3. Build/publish for a linux-x64 or win-x64 runtime identifier in deployment/CI
  4. Use a Linux container or VM for local development on macOS

Example fix

// before
var options = new MsgAuditFinanceOptions { CorpId = corpId, Secret = secret }; // macOS: no default lib
// after
var options = new MsgAuditFinanceOptions { CorpId = corpId, Secret = secret, LibraryPath = "/opt/wework/libWeWorkFinanceSdk_C.so" }; // or run on Linux
Defensive patterns

Strategy: fallback

Validate before calling

if (!OperatingSystem.IsWindows() && !OperatingSystem.IsLinux() && string.IsNullOrWhiteSpace(options.LibraryPath))
    throw new PlatformNotSupportedException("Set LibraryPath explicitly or run on Windows/Linux");

Type guard

bool CanLoadDefaultLibrary() => OperatingSystem.IsWindows() || OperatingSystem.IsLinux();

Try / catch

try { var client = new MsgAuditFinanceClient(options); }
catch (PlatformNotSupportedException ex) when (ex.Message.Contains("Finance")) { /* switch host/container to linux-x64 or configure LibraryPath */ }

Prevention

When it happens

Trigger: Constructing MsgAuditFinanceClient on macOS or another unsupported OS without setting MsgAuditFinanceOptions.LibraryPath, so the default library name resolution fails.

Common situations: Developing on a Mac and deploying without specifying LibraryPath, CI mac runners running integration tests, or containers on unusual platforms lacking the native lib.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12). Data as JSON: /api/errors/3d10cc8fe586f790. Report an issue: GitHub.

Appendix: source

Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceNativeApi.cs:235

            }

            _disposed = true;
            _library.Dispose();
        }

        private static string GetDefaultLibraryName()
        {
            if (FinanceRuntimePlatform.IsWindows)
            {
                return WindowsLibraryName;
            }

            if (FinanceRuntimePlatform.IsLinux)
            {
                return LinuxLibraryName;
            }

            throw new PlatformNotSupportedException(
                "企业微信官方未提供当前操作系统可用的 Finance 会话内容存档原生库。" +
                "请在 Windows 或 Linux 上运行,并在 LibraryPath 中指定对应的官方库。");
        }

        private static string ReadUtf8(IntPtr pointer, int length, string bufferName)
        {
            var bytes = ReadBytes(pointer, length, bufferName);
            return bytes.Length == 0 ? string.Empty : Encoding.UTF8.GetString(bytes);
        }

        private static byte[] ReadBytes(IntPtr pointer, int length, string bufferName)
        {
            if (length < 0)
            {
                throw new InvalidOperationException($"Finance SDK 返回了无效的 {bufferName} 长度:{length}。");
            }

            if (length == 0)

View on GitHub (pinned to be573f6f94)