开发者

How to get string representation of a bit-field enum in C# (MessageQueueErrorCode)?

I get a -2147024891 error code in a MessageQueueException; of type MessageQueueErrorCode. How can I find which errors occurred here?

Note: I have extracted values of this enum using System.Enum.GetValues and then used a LINQ开发者_Go百科 query to find out which ones do fit in this error by using & (and); then getting it's name by System.Enum.GetName and joining them with a ',' separator...anyway: failed!


The error code is 0x80070005. The 7 is the 'facility code', it is Windows. In other words, you didn't get a message queuing error, you got a Windows error. Error code 5 is "Access Denied".

Something wrong with the user account, typically, not enough privileges.


You can cast your errorcode to an enum and use ToString():

string error = ((MessageQueueErrorCode)ex.ErrorCode).ToString();

which should return the Name of the enum value.

Actually i'm unsure what happens if the enum doesn't contain this specific value (maybe an InvalidCastException is thrown) but you can try it out for yourself.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜