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 MessageQueu开发者_StackOverflow中文版e object for it's read write permissions, it returns SendAndReceive. What causes this error and how do you resolve it?
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.
精彩评论