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
- 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.
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
- 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.
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
- 企业微信官方未提供当前操作系统可用的 Finance 会话内容存档原生库。请在 Windows 或 Linux…
- 未知的 PlatformType :
- 微信公众号不支持 IResponseMessageMpNews 响应类型
- 微信公众号不支持 IRequestMessageMiniProgramPage 响应类型
- 无法加载企业微信 Finance 原生库:
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)