{"record":{"id":"91ebb85ee56caab4","repo":"JeffreySu/WeiXinMPSDK","slug":"argumentnullexception-nativeapi-is-null","errorCode":null,"errorMessage":"ArgumentNullException (nativeApi is null)","messagePattern":"ArgumentNullException \\(nativeApi is null\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs","lineNumber":54,"sourceCode":"\n        /// <summary>\n        /// 创建并初始化企业微信会话内容存档 Finance 客户端。\n        /// </summary>\n        /// <param name=\"options\">企业 ID、会话内容存档 Secret、原生库路径及网络选项。</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"options\"/> 为空。</exception>\n        /// <exception cref=\"ArgumentException\">企业 ID、Secret 或超时配置无效。</exception>\n        /// <exception cref=\"PlatformNotSupportedException\">当前操作系统没有企业微信官方 Finance 原生库。</exception>\n        /// <exception cref=\"MsgAuditFinanceException\">官方 Finance SDK 初始化失败。</exception>\n        public MsgAuditFinanceClient(MsgAuditFinanceOptions options)\n            : this(options, CreateNativeApi(options))\n        {\n        }\n\n        internal MsgAuditFinanceClient(MsgAuditFinanceOptions options,\n            IMsgAuditFinanceNativeApi nativeApi)\n        {\n            ValidateOptions(options);\n            _nativeApi = nativeApi ?? throw new ArgumentNullException(nameof(nativeApi));\n            _proxy = options.Proxy ?? string.Empty;\n            _proxyPassword = options.ProxyPassword ?? string.Empty;\n            _timeoutSeconds = options.TimeoutSeconds;\n\n            try\n            {\n                _sdk = _nativeApi.NewSdk();\n                EnsureNativeHandle(_sdk, \"NewSdk\");\n                ThrowIfNativeError(_nativeApi.Init(_sdk, options.CorpId, options.Secret), \"Init\");\n            }\n            catch\n            {\n                ReleaseResources(false);\n                throw;\n            }\n        }\n\n        /// <summary>","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"Missing native SDK binaries (libWeWorkFinanceSdk.so / .dll) so native binding init returns null; DI registration mistakes; manual testing of internal ctor.","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"],"exampleFix":"// before\nvar client = new MsgAuditFinanceClient(options, null);\n// after\nvar client = MsgAuditFinanceClient.Create(options); // loads native API internally","handlingStrategy":"type-guard","validationCode":"IMsgAuditFinanceNativeApi api = MsgAuditFinanceNativeApiFactory.Create(options);\nif (api is null) throw new InvalidOperationException(\"Finance SDK failed to load; check native binaries\");","typeGuard":"static bool HasNativeApi(MsgAuditFinanceOptions o) => MsgAuditFinanceNativeApiFactory.TryCreate(o, out var api) && api is not null;","tryCatchPattern":"try { var client = MsgAuditFinanceClient.Create(options); } catch (ArgumentNullException ex) { log.Fatal(\"Native Finance SDK not available: {0}\", ex.ParamName); throw; }","preventionTips":["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"],"tags":["null-argument","msgaudit","native-sdk","wecom"],"backgroundTag":"null-argument","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"}