問題起源自己安裝好產品的新build,然后用自己本地編譯出來的其中一個DLL去替換到產品中,本來以為可以正常執行,但是卻發現這個新DLL無法被Load,無法被使用。
從Event Viewer里找到了問題描述:
----------------------------------------------------------------------------------------------------
Activation context generation failed for "C:\Program Files\Trend Micro\Messaging Security Agent\instDeferredCustomAction.dll".Error in manifest or policy file "C:\Program Files\Trend Micro\Messaging Security Agent\Microsoft.VC80.MFC.MANIFEST" on line 4. Component identity found in manifest does not match the identity of the component requested.
Reference is Microsoft.VC80.MFC,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50727.4053".
Definition is Microsoft.VC80.MFC,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50727.762".
Please use sxstrace.exe for detailed diagnosis.
----------------------------------------------------------------------------------------------------
解決方法:
只需到產品安裝目錄下找到Microsoft.VC80.MFC.MANIFEST文件,然后修改其version從762變為4053即可
問題原因:
我們的產品由visual studio 2005開發,依賴於Microsoft Visual C++ 2005(用戶的電腦需安裝vcredist_x86.exe,vcredist_x64.exe),我在本地開發時VC的版本是4053(原因是我安裝了Visual C++ 2005 SP1 KB971090的安全更新,VC生成的manifest中引用的ATL/MFC/CRT庫的版本從8.0.50727.762變成了8.0.50727.4053),而出build的機器其編譯時依賴的VC版本是762(http://www.microsoft.com/zh-cn/download/details.aspx?id=5638),所以導致運行時出現此問題。
知識擴展:
1. Event Viewer對此定性為error,描述為SideBySide錯誤,什么是SideBySide?
從Visual Studio 2005開始,微軟創造了SideBySide DLL,創造這種DLL的初衷是許多程序可能會使用不同version的DLL,如果同一個DLL被替換為新version的DLL,可能會導致程序Crash(稱之為DLL Hell),SideBySide DLL正為解決這一問題,也就有了Mainfest文件(與可執行程序或DLL相關)來指明哪個version的DLL可以被執行。Mainfest是個XML的描述文件,對於每個DLL有DLL的Manifest文件,對於每個應用程序Application也有自己的Manifest。
目前對於這個問題的理解至此,希望今后遇到問題都能及時查找原因。不斷進步:)
參考:
1. Working with Visual Studios C++ manifest files
http://stackoverflow.com/questions/588712/working-with-visual-studios-c-manifest-files
2. manifest的作用
http://www.cppblog.com/kyelin/archive/2010/10/09/129163.html
3. 終結VC2005分發包版本問題
http://www.cnblogs.com/mixiyou/archive/2010/02/09/1663620.html
Best Regards