none
GetFileVersionInfoSize() lead to failed to load a Dll If .Net isn't entirely initialized

    Question

  •     Hi,
    I have a very strange problem that lead to failed to load a static Dll.
    I will try to explain it:

    The problem occur in the context of an ActiveX that I try to register. This activeX/Dll have multiple dependencies. In one branch of this dependencies, a Dll is calling the function GetFileVersionInfoSizeW() in its DllMain() function of this Dll. After the called of this function DllMain(), the system crash (First-chance exception at 0x000007fef903aa5e in regsvr32.exe) and I don't have any callstack that tell me where I am. After putting some breakpoint, it seems that the crash is in kernel Dll, near the end of the Dll loading.

    The first strange thing is, if I removed the call to GetFileVersionInfoSizeW() in the DllMain() of my Dll, the problem disappear. Note that even when the problem occur, the function GetFileVersionInfoSizeW() work great, the return size is good, and I have no error with this function (the error appear after the call to DllMain()).
    Here the code of DllMain():
    BOOL APIENTRY DllMain( HMODULE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
    					 )
    {
    	switch (ul_reason_for_call)
    	{
    	case DLL_PROCESS_ATTACH:
    	{
    		HINSTANCE InstanceRshDll1=::GetModuleHandleW(L"MyDllProblem.dll");
    		if(InstanceRshDll1 == NULL)
    		{
    			throw int();
    		}
    		wchar_t ExeFileName[MAX_PATH];
    		GetModuleFileNameW (InstanceRshDll1, ExeFileName, MAX_PATH);
    		DWORD handle;
    		DWORD dwSize  = ::GetFileVersionInfoSizeW(ExeFileName, &handle);
    	}
    	case DLL_THREAD_ATTACH:
    	case DLL_THREAD_DETACH:
    	case DLL_PROCESS_DETACH:
    		break;
    	}
    	return TRUE;
    }

    If I move the call to "GetFileVersionInfoSizeW" in the case "DLL_THREAD_ATTACH", the problem disappear too.

    The very strange thing, appear when I change the order of the Dll loading. If the Microsoft dll "mscoreei.dll" is loaded before my Dll which make a call to GetFileVersionInfoSizeW(), the problem disappear !

    So I have look to the dll which are loaded when the problem occurred and when the problem disappear. It seems that the DLL "mscoree.dll" is always loaded before my dll, but the other DLL "mscoreei.dll" is loaded before, when it works, and after when it's crash.
    It's like some .Net initialization are not really finish (if "mscoreei.dll" isn't loaded yet) and this behavior generate a crash in my Dll...

    Here the list of loaded Dll in the both case:
    When it's crash:
    'regsvr32.exe': Loaded 'C:\Windows\System32\regsvr32.exe', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Program Files\AVAST Software\Avast\snxhk64.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\winsxs\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_fa396087175ac9ac\comctl32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\apphelp.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\AppPatch\AppPatch64\AcGenral.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\sspicli.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\sfc.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\sfc_os.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\userenv.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\profapi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\mpr.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'ImageAtBase0x110000', Loading disabled by Include/Exclude setting.
    'regsvr32.exe': Unloaded 'ImageAtBase0x110000'
    'regsvr32.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\nvinitx.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\detoured.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\Nvd3d9wrapx.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\setupapi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\cfgmgr32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\devobj.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\nvdxgiwrapx.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msvcr110.dll', Symbols loaded.
    'regsvr32.exe': Loaded 'C:\Windows\System32\mfc110u.dll', Symbols loaded.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msvcp110.dll', Symbols loaded.
    'regsvr32.exe': Loaded 'C:\Windows\System32\mscoree.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'E:\Sources\exe\Release_x64\MyDllProblem.dll', Symbols loaded.
    'regsvr32.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Unloaded 'C:\Windows\System32\msvcp110.dll'
    First-chance exception at 0x000007fef903aa5e in regsvr32.exe: 0xC0000005: Access violation reading location 0x000007fee9a5aa56.
    The program '[2392] regsvr32.exe: Native' has exited with code -1 (0xffffffff).


    When it works:
    'regsvr32.exe': Loaded 'C:\Windows\System32\regsvr32.exe', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Program Files\AVAST Software\Avast\snxhk64.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\winsxs\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_fa396087175ac9ac\comctl32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\apphelp.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\AppPatch\AppPatch64\AcGenral.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\sspicli.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\sfc.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\sfc_os.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\userenv.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\profapi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\mpr.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'ImageAtBase0x110000', Loading disabled by Include/Exclude setting.
    'regsvr32.exe': Unloaded 'ImageAtBase0x110000'
    'regsvr32.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\nvinitx.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\detoured.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\Nvd3d9wrapx.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\setupapi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\cfgmgr32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\devobj.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\nvdxgiwrapx.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msvcr110.dll', Symbols loaded.
    'regsvr32.exe': Loaded 'C:\Windows\System32\mfc110u.dll', Symbols loaded.
    'regsvr32.exe': Loaded 'C:\Windows\System32\mscoree.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msvcp110.dll', Symbols loaded.
    'regsvr32.exe': Loaded 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscoreei.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\wininet.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-user32-l1-1-0.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-advapi32-l1-1-0.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-shlwapi-l1-1-0.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-version-l1-1-0.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-normaliz-l1-1-0.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\normaliz.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\iertutil.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\opengl32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\glu32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\ddraw.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\dciman32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\ws2_32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\nsi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\psapi.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msvcr100.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\msvcp100.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\comdlg32.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\winsxs\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.17825_none_2b253c8271ec7765\GdiPlus.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'E:\Sources\exe\Release_x64\MyDllProblem.dll', Symbols loaded.
    LoadLibrary succeeded'regsvr32.exe': Loaded 'C:\Windows\System32\duser.dll', Cannot find or open the PDB file.
    LoadLibrary succeeded'regsvr32.exe': Loaded 'C:\Program Files\WIDCOMM\Bluetooth Software\BtMmHook.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\xmllite.dll', Cannot find or open the PDB file.
    'regsvr32.exe': Loaded 'C:\Windows\System32\clbcatq.dll', Cannot find or open the PDB file.

    I tried to make a simple test project that can reproduce the problem, but I failed to make a example that can be uploaded here.
    I found some workaround to avoid this problem (change Dll loading order, call the function 'GetFileVersionInfoSizeW()' later), but I hope to understand with I have this problem to avoid some new problems in the future and have a real solution to this problem.

    regards,
    François
    Monday, April 29, 2013 4:32 PM

All replies

  • This is exactly why it has been told many, many times not to call from DllMain anything that can cause recursive loader operations.

    So the real solution is, remove from DllMain everything that can be removed or just looks suspicious.

    -- pa



    • Edited by Pavel A Monday, April 29, 2013 5:19 PM
    • Proposed as answer by Jan Ringoš Thursday, May 02, 2013 1:52 PM
    Monday, April 29, 2013 5:15 PM
  •    Hi Pavel A,

    the function 'GetFileVersionInfoSize()' make a recursive load ???

    Or do you think that's the other (parent) Dll (which load the one which made a call to 'GetFileVersionInfoSize()') that make some recursive loader operations ?

    best regards,

    François.

    Thursday, May 02, 2013 10:58 AM
  • the function 'GetFileVersionInfoSize()' make a recursive load ???

    Well, I am not sure how it is implemented, but it can attempt at least to look up the module in the loader database. For this, it will acquire the loader lock. Bummer.

    -- pa
    Thursday, May 02, 2013 1:14 PM