electron中调用了c#的dll,但是在打包后打开exe文件,报错如下:

__proto__
:
Object
FileName
:
"file:///D:\projects\electron-vue\WiFiDockManager_2\outputs\Wi-Fi_Dock_Manager-win32-x64\resources\app\dist\electron\static\DockPipeClient_3.dll"
FusionLog
:
"警告: 程序集绑定日志记录被关闭。
↵要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)设置为 1。
↵注意: 会有一些与程序集绑定失败日志记录关联的性能损失。
↵要关闭此功能,请移除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。
↵"
HResult
:
-2147024894
HelpLink
:
null
InnerException
:
null
Message
:
"未能加载文件或程序集“file:///D:\projects\electron-vue\WiFiDockManager_2\outputs\Wi-Fi_Dock_Manager-win32-x64\resources\app\dist\electron\static\DockPipeClient_3.dll”或它的某一个依赖项。系统找不到指定的文件。"
Source
:
"mscorlib"
StackTrace
:
"   在 System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
↵   在 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
↵   在 System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
↵   在 System.Reflection.Assembly.UnsafeLoadFrom(String assemblyFile)
↵   在 ClrFunc.Initialize(FunctionCallbackInfo<v8::Value>* info)"
TargetSite
:
__proto__
:
Object
message
:
"未能加载文件或程序集“file:///D:\projects\electron-vue\WiFiDockManager_2\outputs\Wi-Fi_Dock_Manager-win32-x64\resources\app\dist\electron\static\DockPipeClient_3.dll”或它的某一个依赖项。系统找不到指定的文件。"
name
:
"System.IO.FileNotFoundException"
__proto__
:
Error: 未能加载文件或程序集“file:///D:\projects\electron-vue\WiFiDockManager_2\outputs\Wi-Fi_Dock_Manager-win32-x64\resources\app\dist\electron\static\DockPipeClient_3.dll”或它的某一个依赖项。系统找不到指定的文件。 at Object.exports.func (D:\projects\electron-vue\WiFiDockManager_2\outputs\Wi-Fi_Dock_Manager-win32-x64\resources\app\node_modules\electron-edge-js\lib\edge.js:177:17) at Module.<anonymous> (file:///D:/projects/electron-vue/WiFiDockManager_2/outputs/Wi-Fi_Dock_Manager-win32-x64/resources/app/dist/electron/worker.js:1:50513) at r (file:///D:/projects/electron-vue/WiFiDockManager_2/outputs/Wi-Fi_Dock_Manager-win32-x64/resources/app/dist/electron/worker.js:1:115) at file:///D:/projects/electron-vue/WiFiDockManager_2/outputs/Wi-Fi_Dock_Manager-win32-x64/resources/app/dist/electron/worker.js:1:923 at file:///D:/projects/electron-vue/WiFiDockManager_2/outputs/Wi-Fi_Dock_Manager-win32-x64/resources/app/dist/electron/worker.js:1:934
message
:
"未能加载文件或程序集“file:///D:\projects\electron-vue\WiFiDockManager_2\outputs\Wi-Fi_Dock_Manager-win32-x64\resources\app\dist\electron\static\DockPipeClient_3.dll”或它的某一个依赖项。系统找不到指定的文件。"
stack
:
"Error: 未能加载文件或程序集“file:///D:\projects\electron-vue\WiFiDockManager_2\outputs\Wi-Fi_Dock_Manager-win32-x64\resources\app\dist\electron\static\DockPipeClient_3.dll”或它的某一个依赖项。系统找不到指定的文件。↵    at Object.exports.func (D:\projects\electron-vue\WiFiDockManager_2\outputs\Wi-Fi_Dock_Manager-win32-x64\resources\app\node_modules\electron-edge-js\lib\edge.js:177:17)↵    at Module.<anonymous> (file:///D:/projects/electron-vue/WiFiDockManager_2/outputs/Wi-Fi_Dock_Manager-win32-x64/resources/app/dist/electron/worker.js:1:50513)↵    at r (file:///D:/projects/electron-vue/WiFiDockManager_2/outputs/Wi-Fi_Dock_Manager-win32-x64/resources/app/dist/electron/worker.js:1:115)↵    at file:///D:/projects/electron-vue/WiFiDockManager_2/outputs/Wi-Fi_Dock_Manager-win32-x64/resources/app/dist/electron/worker.js:1:923↵    at file:///D:/projects/electron-vue/WiFiDockManager_2/outputs/Wi-Fi_Dock_Manager-win32-x64/resources/app/dist/electron/worker.js:1:934"
__proto__
:
Object


​

根据报错内容,可以看到一个文件名错误:

FileName:
"file:///D:\projects\electron-vue\WiFiDockManager_2\outputs\Wi-Fi_Dock_Manager-win32-x64\resources\app\dist\electron\static\DockPipeClient_3.dll"

之所以会报这个错误,是因为我的electron项目调用了c# dll,然后运行的时候找不到该dll。

接下来的解决方法就是想办法在打包的时候将dll也打包。

根据保存内容"resources\app\dist\electron\static\",打包后会将我的DockPipeClient_3.dll放到这个路径下,因此,需要在配置文件中增加相应的配置信息,配置如下:

在项目根目录文件夹.electron-vue中webpack.renderer.config.js文件的

rendererConfig.plugins.push()中

添加如下内容:

 再次打包后发现dll文件已经打包到指定目录中了。

总结:

遇到问题,要具体问题具体分析,不要盲目网上乱搜,最主要的还是要搞清楚出现了什么问题,该如何解决该问题。而不是胡乱一通地网上乱搜,然后试各种无关的方法。

加油!!!

Logo

前往低代码交流专区

更多推荐