创建 MSI 安装程序时缺少 DLL 文件
Curtis Chau
更新: 2025年9月24日
创建 MSI 安装程序时,可能会遇到以下异常:
2025-01-27 16:57:23 - Error: IronBarCodeDetection.Exceptions.IronBarcodeDetectionException: Unexpected error occurred during execution of the IronBarcode Machine Learning library. Please provide details to support@ironsoftware.com for a resolution. ---> System.TypeInitializationException: The type initializer for 'Microsoft.ML.OnnxRuntime.NativeMethods' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.ML.OnnxRuntime.NativeMethods..cctor()
--- End of inner exception stack trace ---
at Microsoft.ML.OnnxRuntime.SessionOptions..ctor()
at Iron.BarCode.Extensions.xjtagg`1..ctor(Stream dfepdx, SessionOptions dfepdy)
at IronBarCodeDetection.BarcodeDetect.PredictObject[TModel](Stream modelStream)
--- End of inner exception stack trace ---
at IronBarCodeDetection.BarcodeDetect.PredictObject[TModel](Stream modelStream)
at IronBarCodeDetection.BarcodeDetect.DetectBarCode()
at Iron.BarCode.Extensions.cuewjf.ehxbbs(BarcodeDetect tlxjvd)
at Iron.BarCode.Extensions.cuewjf.ehxbbr(AnyBitmap tlxjvd, Double tlxjve)
at Iron.BarCode.Extensions.cuewjo.mvanli(AnyBitmap tlxjvd, Double tlxjve)
at Iron.BarCode.Extensions.cuewjo.mvanlf(Image`1 tlxjvd)
at Iron.BarCode.Extensions.cuewjo.mvankh(Object tlxjvd)
at IronBarCode.BarcodeReader.Read(AnyBitmap inputImage, BarcodeReaderOptions barcodeReaderOptions)
at WindowsFormsBarcode.Form1.btnBrowse_Click_1(Object sender, EventArgs e)
2025-01-27 16:57:23 - Error Message: Unexpected error occurred during execution of the IronBarcode Machine Learning library. Please provide details to support@ironsoftware.com for a resolution.
2025-01-27 16:57:23 - Inner Exception: The type initializer for 'Microsoft.ML.OnnxRuntime.NativeMethods' threw an exception.
2025-01-27 16:57:23 - Inner Exception Stack Trace: at Microsoft.ML.OnnxRuntime.SessionOptions..ctor()
at Iron.BarCode.Extensions.xjtagg`1..ctor(Stream dfepdx, SessionOptions dfepdy)
at IronBarCodeDetection.BarcodeDetect.PredictObject[TModel](Stream modelStream)
Text
原因
出现此错误是因为库找不到正常运行所需的文件。
解决方案
为了确保MSI安装程序顺利运行,您必须在设置项目中包含以下三个文件:onnxruntime.dll, IronBarcodeInterop.dll, 和 ReaderInterop.dll。 这些文件在以发布模式构建项目时生成:
onnxruntime.dll: 位于MsiInstallerSample\MsiInstallerSample\bin\ReleaseIronBarcodeInterop.dll: 位于MsiInstallerSample\MsiInstallerSample\bin\Release\runtimes\win-x86\nativeReaderInterop.dll: 位于MsiInstallerSample\MsiInstallerSample\bin\Release\runtimes\win-x86\native
请确保将这三个文件都添加到您的安装项目中,以避免出现此异常。
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。