none
CLR Profiling API and "unhandled exception in unknown module" RRS feed

  • Question

  • Hi!
    I'm trying to use the CLR Profiling API on a WPF process and something strange happens.
    When I run the WPF process in a normal way it runs fine.

    But when I run it with the evnironment variables of my profiling DLL, I get the following exception:

    An unhandled exception of type 'System.IO.FileLoadException' occurred in Unknown Module.
    Additional information: Hash validation failed for file or assembly 'PresentationFramework, Version=4.0.0.0

    (I managed to find it after attaching to the WPF process with a debugger)

    When I try profile a winforms application it doesn't happen.

    Why is it happening and how can I fix it?

    thanks :)


    • Edited by Number 2 Saturday, May 25, 2013 7:05 PM
    Saturday, May 25, 2013 2:54 PM

Answers

  • Hi, I think I figured it out...
    I think it was casued by a memory overrun in my code...

    Thanks :)

    (Should I delete this question? I don't think it will help anybody... )
    • Marked as answer by Number 2 Saturday, June 1, 2013 6:05 PM
    • Edited by Number 2 Saturday, June 1, 2013 6:06 PM
    Saturday, June 1, 2013 6:05 PM

All replies

  • Hi there,

    What API do you use?

    Would you like to post a detailed way to reproduce this scenario?

    Thanks.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, May 26, 2013 11:44 AM
    Moderator
  • I'm using the regular CLR Profiling API (ICorProfilerCallback3 and ICorProfilerCallback2)
    on Window 7 with Visual Studio 2010 Express.

    I'm implementing the Initialize function like this:

    STDMETHODIMP Profiling::Initialize(IUnknown *pICorProfilerInfoUnk)
    {
       	HRESULT res = E_FAIL;
    	DWORD events = COR_PRF_MONITOR_MODULE_LOADS |
    				COR_PRF_MONITOR_THREADS |
    				//COR_PRF_SNAPSHOT_DEFAULT |
    				COR_PRF_ENABLE_STACK_SNAPSHOT;
    
    	res = pICorProfilerInfoUnk->QueryInterface(IID_ICorProfilerInfo, (void**)&m_profinfo);
    	if (SUCCEEDED(res) == true)
    	{
    	    res = pICorProfilerInfoUnk->QueryInterface(IID_ICorProfilerInfo2, (void**)&m_profinfo2);
    		if (FAILED(res) == true) 
    		{
    			m_profinfo2 = NULL;
    		}
    		else 
    		{
    			m_activeProfiler = m_profinfo2;
    			res = pICorProfilerInfoUnk->QueryInterface(IID_ICorProfilerInfo3, (void**)&m_profinfo3);
    			if (FAILED(res) == true) 
    			{
    				m_profinfo3 = NULL;
    			}
    			else
    			{
    				m_activeProfiler = m_profinfo3;
    			}
    		}
    
    		m_activeProfiler->SetEventMask(events);
    		res = S_OK;
    	}
    
    	/*
    			We're getting here an exception when running a WPF application:
    
    			An unhandled exception of type 'System.IO.FileLoadException' occurred in Unknown Module.
    			Additional information: Hash validation failed for file or assembly 'PresentationFramework, Version=4.0.0.0
    
    	*/
    
        Sleep(30000);
        return res;
    
    }
    

    I put there Sleep(30000) so I can attach to the profiled process before it exits/crashes.


    I start the proflied process like this:

        STARTUPINFO startInfo;
        PROCESS_INFORMATION processInfo;
        ZeroMemory( &startInfo, sizeof(startInfo) );
        startInfo.cb = sizeof(startInfo);
        ZeroMemory( &processInfo, sizeof(processInfo) );
    	DWORD creationFlags =  0; 
    
    //     Start the child process. 
        CreateProcess( 
    		NULL,   // No module name (use command line)
            commandLine,			//command line
            NULL,           // Process handle not inheritable
            NULL,           // Thread handle not inheritable
            FALSE,          // Set handle inheritance to FALSE
            creationFlags,              // No creation flags
            envVars,           // Use parent's environment block - Enabling CLR profiling.
            runningPath,           // Use parent's starting directory 
            &startInfo,            // Pointer to STARTUPINFO structure
            &processInfo);           // Pointer to PROCESS_INFORMATION structure
    
    

    Where:
    "creationFlags" = 0
    runningPath is the path of the profiled process
    envVars contains the "COR_ENABLE_PROFILING=1" and "COR_PROFILER" values.

    and before I call "CreateProcess" I enable the privlieges like this:
     EnablePrivilege(SE_DEBUG_NAME, TRUE);

    where EnablePrivilege is:

    bool EnablePrivilege(LPCTSTR lpszPrivilegeName, BOOL bEnable) 
    { 
        HANDLE hToken; 
        TOKEN_PRIVILEGES tp; 
        LUID luid; 
        bool ret; 
    	void* processHandle = GetCurrentProcess();
        if (!OpenProcessToken(processHandle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_READ, &hToken)) 
    	{
    		CloseHandle(processHandle);
            return FALSE; 
    	}
        if (!LookupPrivilegeValue(NULL, lpszPrivilegeName, &luid)) 
        {
    		CloseHandle(processHandle);
            return FALSE; 
    	}
    
        tp.PrivilegeCount           = 1; 
        tp.Privileges[0].Luid       = luid; 
        tp.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0; 
    
        ret = AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL); 
        CloseHandle(hToken); 
    	CloseHandle(processHandle);
    
        return ret; 
    }
    

    Is it enough? :)

    Sunday, May 26, 2013 4:05 PM
  • Hi There,

    Thank you for providing useful information on this issue. I am trying to involve some other one into this case, it will take a little time.

    Thank you for your patience.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, May 26, 2013 11:43 PM
    Moderator
  • Hello.  Nothing here looks obviously wrong.  What ICorProfilerCallback methods do you implement?  Do you create your own thread that calls into the CLR or profiling API to do anything?

    Also, what version of clr.dll gets loaded in the profiled process?

    Thanks,
    Dave

    Friday, May 31, 2013 12:02 AM
  • Hi, I think I figured it out...
    I think it was casued by a memory overrun in my code...

    Thanks :)

    (Should I delete this question? I don't think it will help anybody... )
    • Marked as answer by Number 2 Saturday, June 1, 2013 6:05 PM
    • Edited by Number 2 Saturday, June 1, 2013 6:06 PM
    Saturday, June 1, 2013 6:05 PM
  • No need to delete.  Thanks for updating us on your findings, though.
    Monday, June 3, 2013 11:04 PM