部署 C# windows 程序的时候,经常会遇到在开发环境中跑得好好的,在客户电脑莫名奇妙找不到库,导致无法正常启动程序。虽然depend.exe 也可以查找依赖,但有时候并不好使,费时费力。话不多说,正文开始。
在开发环境下,运行windbg,打开执行文件,按F5 让程序跑起来
会看到正常情况下dll加载信息,这些就是正常运行需要用到的dll
- ModLoad: 2f780000 2f976000 E:\XXXXX\yyyyy\bin\Debug\VideoDll.dll
- ModLoad: 2f780000 2f976000 E:\XXXXX\yyyyy\bin\Debug\VideoDll.dll
- ModLoad: 33e60000 3482c000 E:\XXXXX\yyyyy\bin\Debug\avformat-58.dll
- ModLoad: 33e60000 36902000 E:\XXXXX\yyyyy\bin\Debug\avcodec-58.dll
- ModLoad: 50990000 509fd000 C:\WINDOWS\SysWOW64\MSVCP140.dll
- ModLoad: 5f7d0000 5f7e5000 C:\WINDOWS\SysWOW64\VCRUNTIME140.dll
- ModLoad: 2f980000 2fad5000 E:\XXXXX\yyyyy\bin\Debug\avutil-56.dll
- ModLoad: 7b8d0000 7b95a000 E:\XXXXX\yyyyy\bin\Debug\swresample-3.dll
- ModLoad: 2f980000 2fa0e000 E:\XXXXX\yyyyy\bin\Debug\swscale-5.dll
- ModLoad: 33e60000 3482c000 E:\XXXXX\yyyyy\bin\Debug\avformat-58.dll
- ModLoad: 753b0000 754aa000 C:\WINDOWS\SysWOW64\CRYPT32.dll
- ModLoad: 2f980000 2fad5000 E:\XXXXX\yyyyy\bin\Debug\avutil-56.dll
- ModLoad: 34830000 372d2000 E:\XXXXX\yyyyy\bin\Debug\avcodec-58.dll
- ModLoad: 2fae0000 2fb6e000 E:\XXXXX\yyyyy\bin\Debug\swscale-5.dll
- ModLoad: 372e0000 37435000 E:\XXXXX\yyyyy\bin\Debug\avutil-56.dll
然后在出现问题的电脑执行相同的操作,得到类似的信息,对比信息,可以知道大概是确实啥库导致的,这里缺少的是 MSVCP140.dll。
- ModLoad: 2f780000 2f976000 E:\XXXXX\yyyyy\bin\Debug\VideoDll.dll
- ModLoad: 2f780000 2f976000 E:\XXXXX\yyyyy\bin\Debug\VideoDll.dll
- ModLoad: 33e60000 3482c000 E:\XXXXX\yyyyy\bin\Debug\avformat-58.dll
- ModLoad: 33e60000 36902000 E:\XXXXX\yyyyy\bin\Debug\avcodec-58.dll
-
- ModLoad: 2f980000 2fad5000 E:\XXXXX\yyyyy\bin\Debug\avutil-56.dll
- ModLoad: 7b8d0000 7b95a000 E:\XXXXX\yyyyy\bin\Debug\swresample-3.dll
- ModLoad: 2f980000 2fa0e000 E:\XXXXX\yyyyy\bin\Debug\swscale-5.dll
- ModLoad: 33e60000 3482c000 E:\XXXXX\yyyyy\bin\Debug\avformat-58.dll
- ModLoad: 753b0000 754aa000 C:\WINDOWS\SysWOW64\CRYPT32.dll
- ModLoad: 2f980000 2fad5000 E:\XXXXX\yyyyy\bin\Debug\avutil-56.dll
- ModLoad: 34830000 372d2000 E:\XXXXX\yyyyy\bin\Debug\avcodec-58.dll
- ModLoad: 2fae0000 2fb6e000 E:\XXXXX\yyyyy\bin\Debug\swscale-5.dll
- ModLoad: 372e0000 37435000 E:\XXXXX\yyyyy\bin\Debug\avutil-56.dl
还有一种情况是dll库都在,但是加载dll库报错,也可以通过加载的dll 顺序看出来。