JeffreySu/WeiXinMPSDK · error · PlatformNotSupportedException

企业微信 Finance 会话内容存档原生库仅支持 Windows 和 Linux。

Error message

企业微信 Finance 会话内容存档原生库仅支持 Windows 和 Linux。

What it means

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.

Solutions

  1. Run the service on Windows or Linux (the only platforms with an official Finance SDK).
  2. For local dev on macOS, point the code at a Linux container or a remote Windows/Linux test environment.
  3. Skip/condition finance-related tests so they only execute on supported OSes (e.g. [SkippableFact] with OS check).
  4. If you control the runtime image, use a linux-x64 Docker base image and ship the .so SDK.

Example fix

// before
var api = MsgAuditFinanceNativeApi.Create(); // throws on macOS
// after
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
    throw new SkipTestException("Finance SDK requires Windows or Linux");
}
var api = MsgAuditFinanceNativeApi.Create();
Defensive patterns

Strategy: validation

Validate before calling

bool supported = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
if (!supported) throw new PlatformNotSupportedException("Finance SDK requires Windows or Linux");

Type guard

static bool IsFinanceSupported() =>
    RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

Try / catch

try { var api = MsgAuditFinanceNativeApi.Create(); }
catch (PlatformNotSupportedException) { logger.LogWarning("Finance archiving disabled on this OS"); return null; }

Prevention

When it happens

Trigger: 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.

Common situations: Developing/testing message-archiving code on a MacBook; hosting the service on an unsupported platform; unit tests running on macOS CI agents.

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/a42fb88608f46aad. Report an issue: GitHub.

Appendix: source

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

        /// <param name="path">动态库路径或文件名。</param>
        /// <returns>已经加载的动态库句柄。</returns>
        public static FinanceLibraryHandle Load(string path)
        {
            if (FinanceRuntimePlatform.IsWindows)
            {
                var handle = WindowsNative.LoadLibrary(path);
                if (handle == IntPtr.Zero)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error(),
                        $"无法加载企业微信 Finance 原生库:{path}");
                }

                return new FinanceLibraryHandle(handle, true, false);
            }

            if (!FinanceRuntimePlatform.IsLinux)
            {
                throw new PlatformNotSupportedException(
                    "企业微信 Finance 会话内容存档原生库仅支持 Windows 和 Linux。");
            }

            IntPtr linuxHandle;
            var useLegacy = false;
            try
            {
                linuxHandle = LinuxNative.DlOpen(path, RtldNow);
            }
            catch (DllNotFoundException)
            {
                useLegacy = true;
                linuxHandle = LinuxLegacyNative.DlOpen(path, RtldNow);
            }

            if (linuxHandle == IntPtr.Zero)
            {
                var detail = useLegacy ? LinuxLegacyNative.GetError() : LinuxNative.GetError();

View on GitHub (pinned to be573f6f94)