{"record":{"id":"9a445bd063a9ed43","repo":"JeffreySu/WeiXinMPSDK","slug":"finance-path","errorCode":null,"errorMessage":"无法加载企业微信 Finance 原生库：{path}","messagePattern":"无法加载企业微信 Finance 原生库：(.+?)","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"critical","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceNativeApi.cs","lineNumber":352,"sourceCode":"        {\n            _handle = handle;\n            _isWindows = isWindows;\n            _useLegacyLibDl = useLegacyLibDl;\n        }\n\n        /// <summary>\n        /// 加载动态库并返回受控句柄。\n        /// </summary>\n        /// <param name=\"path\">动态库路径或文件名。</param>\n        /// <returns>已经加载的动态库句柄。</returns>\n        public static FinanceLibraryHandle Load(string path)\n        {\n            if (FinanceRuntimePlatform.IsWindows)\n            {\n                var handle = WindowsNative.LoadLibrary(path);\n                if (handle == IntPtr.Zero)\n                {\n                    throw new Win32Exception(Marshal.GetLastWin32Error(),\n                        $\"无法加载企业微信 Finance 原生库：{path}\");\n                }\n\n                return new FinanceLibraryHandle(handle, true, false);\n            }\n\n            if (!FinanceRuntimePlatform.IsLinux)\n            {\n                throw new PlatformNotSupportedException(\n                    \"企业微信 Finance 会话内容存档原生库仅支持 Windows 和 Linux。\");\n            }\n\n            IntPtr linuxHandle;\n            var useLegacy = false;\n            try\n            {\n                linuxHandle = LinuxNative.DlOpen(path, RtldNow);\n            }","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceNativeApi.cs#L334-L370","documentation":"FinanceLibraryHandle.Load could not load the WeChat Work Finance native DLL on Windows: LoadLibraryW returned IntPtr.Zero. The wrapper throws Win32Exception including the Win32 error code and the requested path. The library file is missing, blocked, or its dependencies cannot be resolved.","triggerScenarios":"Constructing the finance API with a LibraryPath that points to a nonexistent/moved libWeWorkFinanceSdk.dll; the DLL's dependent DLLs (VC runtime, OpenSSL) missing; the file blocked by Windows ('downloaded from internet' mark); running x64 process with x86 dll or vice versa (returns error 193 'bad exe format').","commonSituations":"Deploying without copying the SDK dll next to the app; CI/Docker builds on windows where the dll wasn't published; antivirus quarantine of the dll.","solutions":["Check the path/relative path in LibraryPath and that the dll exists in the output directory (CopyToOutputDirectory=true).","Read the Win32Exception error code: 126 = file not found (fix path/dependencies), 193 = wrong bitness (use matching x64/x86 dll), 5 = access denied.","Install missing dependencies of the SDK (VC++ redistributables) and unblock the file (Unblock-File).","On load failure, prefer an absolute path to the SDK dll over a bare file name."],"exampleFix":"// before\nvar api = MsgAuditFinanceNativeApi.Create(); // defaults to \"libWeWorkFinanceSdk.dll\" not copied\n// after\nvar path = Path.Combine(AppContext.BaseDirectory, \"libWeWorkFinanceSdk_Csharp\", \"libWeWorkFinanceSdk.dll\");\nif (!File.Exists(path)) throw new FileNotFoundException(\"Finance SDK dll missing\", path);\nvar api = MsgAuditFinanceNativeApi.Create(path);","handlingStrategy":"try-catch","validationCode":"var path = Path.Combine(AppContext.BaseDirectory, \"libWeWorkFinanceSdk.dll\");\nif (!File.Exists(path)) throw new FileNotFoundException(\"Finance SDK dll not deployed\", path);","typeGuard":"static bool LibraryAvailable(string path) => File.Exists(path) && Path.GetExtension(path) == \".dll\";","tryCatchPattern":"try { return FinanceLibraryHandle.Load(path); }\ncatch (Win32Exception ex) when (ex.NativeErrorCode == 126) { throw new InvalidOperationException(\"Finance dll or its dependencies missing at \" + path, ex); }\ncatch (Win32Exception ex) when (ex.NativeErrorCode == 193) { throw new InvalidOperationException(\"Finance dll bitness mismatch\", ex); }","preventionTips":["Set CopyToOutputDirectory for the native dll in csproj.","Pin absolute LibraryPath in production config.","Keep VC++ redistributables in deployment images."],"tags":["native-library","dll-load","windows"],"backgroundTag":"file-not-found","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"}