private unsafe static void GenerateErrorReportForDump(LowLevelList <byte[]> serializedExceptions)
        {
            checked
            {
                int loadedModuleCount = RuntimeAugments.GetLoadedModules(null);
                int cbModuleHandles   = sizeof(System.IntPtr) * loadedModuleCount;
                int cbFinalBuffer     = sizeof(ERROR_REPORT_BUFFER_HEADER) + sizeof(SERIALIZED_ERROR_REPORT_HEADER) + cbModuleHandles;
                for (int i = 0; i < serializedExceptions.Count; i++)
                {
                    cbFinalBuffer += serializedExceptions[i].Length;
                }

                byte[] finalBuffer = new byte[cbFinalBuffer];
                fixed(byte *pBuffer = finalBuffer)
                {
                    byte *pCursor     = pBuffer;
                    int   cbRemaining = cbFinalBuffer;

                    ERROR_REPORT_BUFFER_HEADER *pDacHeader = (ERROR_REPORT_BUFFER_HEADER *)pCursor;

                    pDacHeader->WriteHeader(cbFinalBuffer);
                    pCursor     += sizeof(ERROR_REPORT_BUFFER_HEADER);
                    cbRemaining -= sizeof(ERROR_REPORT_BUFFER_HEADER);

                    SERIALIZED_ERROR_REPORT_HEADER *pPayloadHeader = (SERIALIZED_ERROR_REPORT_HEADER *)pCursor;

                    pPayloadHeader->WriteHeader(serializedExceptions.Count, loadedModuleCount);
                    pCursor     += sizeof(SERIALIZED_ERROR_REPORT_HEADER);
                    cbRemaining -= sizeof(SERIALIZED_ERROR_REPORT_HEADER);

                    // copy the serialized exceptions to report buffer
                    for (int i = 0; i < serializedExceptions.Count; i++)
                    {
                        int cbChunk = serializedExceptions[i].Length;
                        Array.CopyToNative(serializedExceptions[i], 0, (IntPtr)pCursor, cbChunk);
                        cbRemaining -= cbChunk;
                        pCursor     += cbChunk;
                    }

                    // copy the module-handle array to report buffer
                    System.IntPtr[] loadedModuleHandles = new System.IntPtr[loadedModuleCount];
                    RuntimeAugments.GetLoadedModules(loadedModuleHandles);
                    Array.CopyToNative(loadedModuleHandles, 0, (IntPtr)pCursor, loadedModuleHandles.Length);
                    cbRemaining -= cbModuleHandles;
                    pCursor     += cbModuleHandles;

                    Debug.Assert(cbRemaining == 0);
                }

                UpdateErrorReportBuffer(finalBuffer);
            }
        }
            /// <summary>
            /// Serializes the exception metadata and SerializedExceptionData
            /// </summary>
            public unsafe byte[] Serialize()
            {
                checked
                {
                    byte[] serializedData = new byte[sizeof(ExceptionMetadataStruct) + SerializedExceptionData.Length];
                    fixed(byte *pSerializedData = serializedData)
                    {
                        ExceptionMetadataStruct *pMetadata = (ExceptionMetadataStruct *)pSerializedData;

                        pMetadata->ExceptionId      = ExceptionMetadata.ExceptionId;
                        pMetadata->InnerExceptionId = ExceptionMetadata.InnerExceptionId;
                        pMetadata->ThreadId         = ExceptionMetadata.ThreadId;
                        pMetadata->NestingLevel     = ExceptionMetadata.NestingLevel;
                        pMetadata->ExceptionCCWPtr  = ExceptionMetadata.ExceptionCCWPtr;

                        Array.CopyToNative(SerializedExceptionData, 0, (IntPtr)(pSerializedData + sizeof(ExceptionMetadataStruct)), SerializedExceptionData.Length);
                    }

                    return(serializedData);
                }
            }