MessageQueueErrorCode -1073741536, Hex Code -0x3FFFFEE0 MSMQ C# .NET 4.0
Error receiving/ processing MSMQ messages in QueueReceiver, exception: System.Messaging.MessageQueueException (0x80004005)
at System.Messaging.MessageQueue.EndAsyncOperation(IAsyncResult asyncResult)
at System.Messaging.MessageQueue.EndPeek(IAsyncResult asyncResult)
at OnlineAVL.Services.Core.MessageQueueReceiver`1._receiverMessageQueue_PeekCompleted(Object sender, PeekCompletedEventArgs e)
It is more confusing because a simple sample application does not throw this error. I checked everything from project files to compiler and cleaning up code.
After debugging for 2 days, I found that the problem is because BeginPeek() is called in a method which is running on another thread, than the main application. This error happens on both MTA and STA apartment states, but only happens in Win 2003 server.
The same code runs fine in 2008 server (Vista) and above. This is not specific to x86 or x64.
The fix was to check for the OS version and determine whether to run this code in a thread or not. Here is the sample code:
public static bool RunInNewThread()
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
if (Environment.OSVersion.Version.Major > 5)
//2003 is 5, Vista and beyond in 6.