Skip to main content

 none
custom windows error reports are not being sent to the WER server in Windows 8, but the same code is working for WIN-7 and Vista RRS feed

  • Question

  • Hi,

    I am using kernel32 functions using DllImport attribute in C# app,
    below is the sample code :

        Publc class WERWrapperCode
        {
            public const int WerRegFileTypeOther = 2;
            public const int WER_FILE_ANONYMOUS_DATA = 2;
            public static bool IsLogFileRegistered { get; set; }

            [DllImport("wer.dll", CharSet = CharSet.Unicode, SetLastError = true)]
            public static extern int WerReportAddDump(IntPtr hReportHandle,
            IntPtr hProcess, IntPtr hThread, WER_DUMP_TYPE dumpType, IntPtr pExceptionParam, IntPtr pDumpCustomOptions, int dwFlags);
            [DllImport("wer.dll", CharSet = CharSet.Unicode, SetLastError = true)]
            public static extern int WerReportCreate(string pwzEventType,
            WER_REPORT_TYPE repType, IntPtr pReportInformation, ref IntPtr phReportHandle);
            [DllImport("wer.dll", CharSet = CharSet.Unicode, SetLastError = true)]
            public static extern int WerReportSetParameter(IntPtr hReportHandle, int dwparamID, string pwzName, string pwzValue);
            [DllImport("wer.dll", CharSet = CharSet.Unicode, SetLastError = true)]
            public static extern int WerReportSubmit(IntPtr hReportHandle, WER_CONSENT consent, int dwFlags, ref IntPtr pSubmitResult);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int WerRegisterFile(string pwzFile, int regFileType, int dwFlags);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int WerUnregisterFile(string pwzFile);


             public static void RegisterLogFileForWER(string fileToAttach)
            {
                 try
                {
                    WerRegisterFile(fileToAttach, WerRegFileTypeOther, WER_FILE_ANONYMOUS_DATA);
                    IsLogFileRegistered = true;
                }
                catch { IsLogFileRegistered = false; }
            }


            public void GenerateErrorReport(object exceptionObject)
            {
                var zero = IntPtr.Zero;

                if (!IsLogFileRegistered)
                    RegisterLogFileForWER(@"C:\Logs\test.log");

                WerReportCreate("CustomError", WER_REPORT_TYPE.WerReportNonCritical, IntPtr.Zero, ref zero);
                if (zero == IntPtr.Zero) return;
               
                var assembly = Assembly.GetExecutingAssembly();
                var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
               
                WerReportSetParameter(zero, 0, "P1", fvi.FileName);
                WerReportSetParameter(zero, 1, "P2", fvi.ProductVersion);

                var exception = exceptionObject as Exception;
                if (exception != null)
                {
                    WerReportSetParameter(zero, 2, "P3", exception.GetType().FullName);
                    WerReportSetParameter(zero, 3, "P4", exception.Message);
                    WerReportSetParameter(zero, 4, "P5", exception.StackTrace);
                }

                var currentProcess = Process.GetCurrentProcess().Handle;
                WerReportAddDump(zero, currentProcess, IntPtr.Zero, WER_DUMP_TYPE.WerDumpTypeMiniDump, IntPtr.Zero, IntPtr.Zero, 0);

                var pSubmitResult = IntPtr.Zero;
                WerReportSubmit(zero, WER_CONSENT.WerConsentNotAsked, 16, ref pSubmitResult);
            }
        }

    This code is working fine in others OS for Vista and WIN-7, in WIN - 8 it is saying report not sent when i try to add minidump it says that heap dump creation failed, but when i exclude that by commenting WerReportAddDump in above code then also it is not sending the error report.

    Please let me know what is missing. I have checked the WER setting it is enabled and working fine because other apps are able to send the reports like IE.

    One more difference i saw is the number of request sent to Watson server from Vista and WIN-7 are 3 and from WIN-8 is only one.

    Please provide your valuable input.

    Thanks in advance.

    Manoj

    Manoj Shukla

    Tuesday, October 30, 2012 11:48 AM

All replies

  • I'm not this APIs area dev expert, and I have not tested out the problem, so I involved others senior engineer to try to help and reply to you.

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us

    Thursday, November 1, 2012 4:08 AM
    Moderator
  • Hi Manoj,

    Thank you for the question.   My team has reviewed the sample code and we was unable to reproduce the issue here with Windows 8.   In the sample code, can you advise what line it is failing?   And also include the call stack of any exception?

    We may need to open a paid support case to review further given we cannot reproduce here but want to check if we can get any further details.

    Thanks,

    Nathan Manis

    Monday, November 5, 2012 7:07 PM