views:

245

answers:

3

I'm attempting to debug an ASP.NET application. It's particularly difficult as the bug only occurs in the released code deployed to production. It cannot be reproduced in the development or test environments.

I'd like to investigate further by creating a dump file at a particular line in the code where the problem is happening. However the production environment cannot be taken down at any point due to business requirements. That's also why remote debugging can't be used.

Does anyone know how I can force a dump file to be created for w3wp.exe at a certain point in the managed code, yet still allow the rest of the application to operate normally?

+1  A: 

I think you will find plenty of useful information in Tess Ferrandez' blog.

Fredrik Mörk
A: 

Hi there.

Just to add to Frederik's post, have a look a Tee's blog, but focus on using AdPlus which is command line tool that will help you create dump files for running processes. Tess has a number of examples of how to use this tool for collecting dump files to debug with.

Cheers. Jas.

Jason Evans
+1  A: 

If the web-app has the access rights to do so and you can deploy new code the environment, then you can manually create the dump file with the use of the DbgHelp API:

[DllImport("DbgHelp.dll", SetLastError = true)]
        static extern bool MiniDumpWriteDump(IntPtr ProcessHandle, int ProcId, IntPtr FileHandle, int DumpType, IntPtr ExcpInfo, IntPtr UserInfo, IntPtr ExtInfo);
    private static void DumpIt()
    {
        string outputFileName = "c:\\mem.dmp";

        using (FileStream stream = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
        {
            using (Process proc = Process.GetCurrentProcess())
            {
                MiniDumpWriteDump(proc.Handle, proc.Id, stream.SafeFileHandle.DangerousGetHandle(), (int)0x00000306, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
            }
        }
    }
S.Skov