开发者

What are the causes and solutions to a CS0122 error when sending onto an MSMQ queue from C#?

开发者 https://www.devze.com 2022-12-27 16:31 出处:网络
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 (resul

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号