To start: I get no error message; just a hang condition. If I could get an Exception, I could probably figure this out for myself. Instead, .NET just hangs, cold and unresponsive.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Here's the short concept of what I'm doing (no code examples here as the concept should be simple enough to implement by any interested troubleshooters):
- Make a struct called KeyValuePair with two fields: a Key and a Value, both String types. Mark the KeyValuePair struct as [Serializable].
- Make a subclass of Hashtable called HashSet and override the Add method to guarantee that all Keys are unique at all times when Add(key, value) is used. Mark the HashSet subclass as [Serializable].
- Make a subclass of HashSet called SpecializedHashSet. Overload the Add method to receive a KeyValuePair struct and forward the field data to the other Add method (of HashSet). Mark SpecializedHashSet as [Serializable].
- Make a subclass of ArrayList called ArraySet and override most of its methods to also guarantee that its values will always be unique within the array. Mark the ArraySet subclass as [Serializable].
- Create a new class that will be part of a bigger package that will be created in the next step. Call it PackageWrapperComponent and add a few simple properties (Int32, Boolean, and String). Add also a SpecializedHashSet property.
- Create a new class that will be the package wrapper you intend to send via MSMQ from client to server. Call it PackageWrapper and give it a few simple properties and one ArraySet property. Also add a PackageWrapperComponent property to hold a reference an object of the class written in step 5.
- Create two simple console application projects, both with references to the project containing the code written for steps 1-6: one to send the MSMQ message and one to receive the MSMQ message. The two applications will run on two physically separate machines.
- The Client will create a PackageWrapper, set all property values (including a fully populated PackageWrapperComponent), and send the PackageWrapper via MSMQ to the server in a BinaryMessageFormatter message.
- The Server will receive the message and attempt to extract the PackageWrapper from the MSMQ message body.
At this point, .NET hangs on the server when all properties are initialized.
I can avoid the hang by NOT initializing the SpecializedHashSet property of the PackageWrapperComponent of the PackageWrapper object. In other words, when the SpecializedHashSet instance is left null on the PackageWrapperComponent, everything works. But once I initialized SpecializedHashSet, even to an empty SpecializedHashSet, the server hangs when it attempts to extract the message body. Additionally, if I demote the SpecializedHashSet to a Hashtable, everything works, even when initialized. Naturally, I need to use SpecializedHashSet and not Hashtable in my production code. Is there some serialization/deserialization condition which prevents developers from working with subclasses of Hashtable Or am I (hopefully) just missing some mundane detail
I have wrapped the particular server code in a try/catch block, but no Exception is ever thrown. .NET just hangs cold. I have placed extensive debugging WriteLine() lines around the code and have isolated the line that hangs:
public void AcceptAsyncMessage(Object source, ReceiveCompletedEventArgs asyncResult) {
MessageQueue msmqEventQueue;
Message msmqMessage;
Object messageBody;
Console.WriteLine("Woken up by MSMQ. Attaching to the local Microsoft Message Queue to receive the message...");
// Connect to the queue.
msmqEventQueue = (MessageQueue)source;
Console.WriteLine("Connected to the local receiving Microsoft Message Queue.");
// Momentarilly end the asynchronous Receive operation to extract the message body.
try {
Console.WriteLine("Extracting the message entity...");
msmqMessage = (Message)msmqEventQueue.EndReceive(asyncResult.AsyncResult);
Console.WriteLine("Extracting the message body...");
// .NET hangs right here:
messageBody = msmqMessage.Body;
Console.WriteLine("The message body has been retrieved.");
}
catch (Exception e) {
Console.WriteLine("Exception encountered: {0}", e.Message);
}
// Further code which analyses and processes the messageBody has been omitted as it is never reached.
}
I see all Console messages up to "Extracting the message body…", but I see neither "The message body has been retrieved." nor "Exception encountered:". .NET freezes when attempting to assign the Message.Body value to an Object variable. What's up It may be only my opinion, by I feel that .NET should -- at least -- throw an Exception rather than hang like this. How do I make this work
My environment:
Microsoft Visual Studio 2005 (C#.NET)
Microsoft .NET 2.0
Microsoft Windows XP Professional on both Client and Server (for now, will be on Windows 2003 Server when this project moves to production).
While I'd love to provide all my actual code, I cannot for proprietary reasons and because, frankly, there are many hundreds of lines of code implementing this simple concept in my real application.

MSMQ Serializable Hashtable subclass causes a hang when extracting Message.Body
johnsmith2005
Running code in debugger throws following exception when Message body is retrieved as an object. During this step, Message body is deserialized but it can not find the constructor for the SpecializedHashSet.
System.Exception was unhandled by user code
Message="The constructor to deserialize an object of type 'SharedLib.SpecializedHashSet' was not found."
Source="MSMQServer"
StackTrace:
at
MSMQServer.ServerWorker.AcceptAsyncMessage(Object source, ReceiveCompletedEventArgs asyncResult) in MSMQNestedClassTrouble\MSMQServer\ServerWorker.cs:line 71
at
System.Messaging.MessageQueue.OnRequestCompleted(IAsyncResult asyncResult)
at System.Messaging.MessageQueue.AsynchronousRequest.RaiseCompletionEvent(Int32 result, NativeOverlapped* overlappedPointer)
The issue is with inheriting from a custom-serialized class (Hashtable in your case). You’d basically have to implement ISerializable + provide a “deserialization constructor”.
Following article describes details about serialization and deserialization of Hashtable;
http://msdn.microsoft.com/msdnmag/issues/02/07/net/default.aspx
ujjubee
Until we can identify who is responsible for supporting .NET's implementation of MSMQ, I will continue to post updates to both forms mentioned in this thread. I can't help but feel that this is the right place, being named ".NET Framework Networking and Communication". MSMQ is a Microsoft network communications platform.
I have created a new Visual Studio 2005 Solution file with all the necessary C# Projects and source files. It is fully operational -- just update the MSMQ paths, compile the solution, and give it a try. You will see the same hanging problem that I have described above. This Solution is far simpler than my actual implementation, yet it exhibits exactly the same behavior.
The entire source (without documentation) is available at: http://www.astech-intermedia.com/xfer/MSMQNestedClassTrouble.zip
Before you can run this, you must:
Thank you very much for your time. This looks like a possible bug in .NET, but I'd like others to confirm or deny this notion. I'd prefer that this were a bug in my own code.
beginner.net
I understand your situation. However trust me that this forum or any people that are owning this forum don't use MSMQ.
I don't know who supports MSMQ from the forums. I will find out.
DKR2006
We don't handle MSMQ questions in this forum
May be this forum can help you out
http://forums.microsoft.com/MSDN/ShowForum.aspx ForumID=46&SiteID=1
Dorie Hannan
Add this to the HashSet class:
public
HashSet(): base() {} public HashSet(SerializationInfo info, StreamingContext context): base(info, context) {} public override void GetObjectData(SerializationInfo info, StreamingContext context) {base.GetObjectData(info, context);
}
Further, add similar constructors to your SpecializedHashSet class.
Also, in the server code, do not rethrow the exception - since it is caught and swallowed internally by system.messaging code (which "might" be a bug in itself) - thats the reason it appears to you that the server is unresponsive.
HTH.
TobyRickett
*bump*
This issue is imperative to our company. A new, but important feature of our application depends on this solution working. Can anyone give this a try
Thanks!
Annonnymus
This has nothing to do with ASP.NET, nor am I using XML serialization. I came here because MSMQ is, after all, a networking service and I am, as stated, using C#.NET.
Are you sure the "ASP.NET and XML Serialization" forum can be of service, or am I being set up for another run-around
I'm sorry this is a bitter reply. I get the feeling that I won't get any help even at the other forum.