tags:

views:

83

answers:

1

Having created a System.Messaging.MessageQueue using the MessageQueue(string queuePath) constructor, attempting to use MessageQueue.Send(obj) results in a 'Unable to generate a temporary class (result=1)' exception with the additional text: 'error CS0122: 'System.__ComObject' is inaccessible due to its protection level'.

The queue itself has full control given to EVERYONE. When querying the MessageQueue object for it's read write permissions, it returns SendAndReceive. What causes this error and how do you resolve it?

+4  A: 

Oh joy, a runtime error mixed with a compile time error. MessageQueue uses XML serialization to serialize objects that are not Message. If you haven't use sgen.exe to create a serialization assembly at build time (you really should) then it generates the assembly at runtime.

Clearly that fails, whatever object you are passing to Send() does not support XML serialization. Judging from the error message, that might be because it is not a simple .NET class. Solve it by making it a simple .NET class, one that survives XmlSerializer.Serialize() and back.

Hans Passant
This is indeed the correct answer to my problem, but as it happens not the solution to my problem. I ended up writing my own formatter implementing IMessageFormatter that was able to serialize the data in the format that the partner application could handle.Putting a flat unwrapped string onto a queue from .net is way more difficult then it should be.
Erick