JeffreySu/WeiXinMPSDK · error · ArgumentNullException
ArgumentNullException (nativeApi is null)
Error message
ArgumentNullException (nativeApi is null)
What it means
The internal MsgAuditFinanceClient constructor validates its dependencies and throws ArgumentNullException when the nativeApi parameter (the IMsgAuditFinanceNativeApi wrapper over the Finance SDK) is null. Without it the client cannot perform any SDK call.
Solutions
- Ensure the WeWork Finance native SDK binaries are present and loadable before constructing the client (check platform + path)
- Use the public factory (e.g. MsgAuditFinanceClient.Create(options)) instead of the internal ctor and let it build the native API
- If in tests, provide a fake IMsgAuditFinanceNativeApi rather than null
Example fix
// before var client = new MsgAuditFinanceClient(options, null); // after var client = MsgAuditFinanceClient.Create(options); // loads native API internally
Defensive patterns
Strategy: type-guard
Validate before calling
IMsgAuditFinanceNativeApi api = MsgAuditFinanceNativeApiFactory.Create(options);
if (api is null) throw new InvalidOperationException("Finance SDK failed to load; check native binaries"); Type guard
static bool HasNativeApi(MsgAuditFinanceOptions o) => MsgAuditFinanceNativeApiFactory.TryCreate(o, out var api) && api is not null;
Try / catch
try { var client = MsgAuditFinanceClient.Create(options); } catch (ArgumentNullException ex) { log.Fatal("Native Finance SDK not available: {0}", ex.ParamName); throw; } Prevention
- Ship and verify native SDK binaries per-platform at deploy time
- Prefer public factory methods over the internal constructor
- Fail fast at startup with a connectivity/loading probe
When it happens
Trigger: Constructing the client via the internal factory/ctor with a null native API — typically when a factory method failed to load the native Finance SDK library and passed null, or in unit tests supplying null directly.
Common situations: Missing native SDK binaries (libWeWorkFinanceSdk.so / .dll) so native binding init returns null; DI registration mistakes; manual testing of internal ctor.
Related errors
- Finance SDK 返回的会话内容为空。
- 单次拉取条数必须介于 1 和 1000 之间。
- 无法解析 Finance SDK 返回的会话内容 JSON。
- buttonGroupBase不可以为空!
- data
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/91ebb85ee56caab4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs:54
/// <summary>
/// 创建并初始化企业微信会话内容存档 Finance 客户端。
/// </summary>
/// <param name="options">企业 ID、会话内容存档 Secret、原生库路径及网络选项。</param>
/// <exception cref="ArgumentNullException"><paramref name="options"/> 为空。</exception>
/// <exception cref="ArgumentException">企业 ID、Secret 或超时配置无效。</exception>
/// <exception cref="PlatformNotSupportedException">当前操作系统没有企业微信官方 Finance 原生库。</exception>
/// <exception cref="MsgAuditFinanceException">官方 Finance SDK 初始化失败。</exception>
public MsgAuditFinanceClient(MsgAuditFinanceOptions options)
: this(options, CreateNativeApi(options))
{
}
internal MsgAuditFinanceClient(MsgAuditFinanceOptions options,
IMsgAuditFinanceNativeApi nativeApi)
{
ValidateOptions(options);
_nativeApi = nativeApi ?? throw new ArgumentNullException(nameof(nativeApi));
_proxy = options.Proxy ?? string.Empty;
_proxyPassword = options.ProxyPassword ?? string.Empty;
_timeoutSeconds = options.TimeoutSeconds;
try
{
_sdk = _nativeApi.NewSdk();
EnsureNativeHandle(_sdk, "NewSdk");
ThrowIfNativeError(_nativeApi.Init(_sdk, options.CorpId, options.Secret), "Init");
}
catch
{
ReleaseResources(false);
throw;
}
}
/// <summary>View on GitHub (pinned to be573f6f94)