Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Eventlog.WriteEntry throws "Win32Exception / The parameter is incorrect"

$
0
0

//See if we need to truncate our buffer so we don't generate error while logging

  private const int MAX_ENTRY_SIZE = 32766;

if (buffer1.Length > MAX_ENTRY_SIZE) { string buffer2 = buffer1.Substring(0, MAX_ENTRY_SIZE - 1); EventLog.WriteEntry(sourceName, buffer2 , type, this.EventId); } else { EventLog.WriteEntry(sourceName, buffer1, type, this.EventId); }

What causes EventLog.WriteEntry to throw "Win32Exception / The parameter is incorrect".  The parameters all look correct to me.  

Note, type is Error and EventId is 1.

Here is the EventLogInternal code that is blowing up.  Appears to blow up on GCHandle.Alloc for some odd reason:

IntPtr[] ptrArray = new IntPtr[strings.Length];
            GCHandle[] handleArray = new GCHandle[strings.Length];
            GCHandle handle = GCHandle.Alloc(ptrArray, GCHandleType.Pinned);
            try
            {
                for (int j = 0; j < strings.Length; j++)
                {
                    handleArray[j] = GCHandle.Alloc(strings[j], GCHandleType.Pinned);
                    ptrArray[j] = handleArray[j].AddrOfPinnedObject();
                }
                byte[] userSID = null;
                if (!Microsoft.Win32.UnsafeNativeMethods.ReportEvent(this.writeHandle, (short) type, category, eventID, userSID, (short) strings.Length, rawData.Length, new HandleRef(this, handle.AddrOfPinnedObject()), rawData))
                {
                    throw SharedUtils.CreateSafeWin32Exception();
                }
            }
I wonder if the EventLog has reserved characters.  The buffer has a bunch of web page content stuff related to HttpParseException.  What characters are allowed/disallowed?

scott




Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>