0

this my first question so sorry if the format isn't perfect yet.

I've a small app communicating via an MSMQ, so I decided to make an aspx webpage to monitor the content of that msmq.

I've tested that page in our acceptance server, works perfectly fine. However, when I test it in our prod server, if the msmq isn't empty, I have an error page saying "SERVER ERROR IN MSMQ MONITORING : Cannot find a formatter capable of reading this message".

Here's the relevant section of the code :

@{
    var errorMessage = "";
    string queueName = ".\\Private$\\cotfollowupqueue";
    System.Messaging.MessageQueue myqueue = new System.Messaging.MessageQueue(@queueName);
    System.Messaging.Message[] msgs = new System.Messaging.Message[0];

    try { 
    msgs= myqueue.GetAllMessages();
    }
    catch (Exception ex)
    {
        errorMessage = "An error occured : " + ex.Message.ToString();
    }
    myqueue.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(AwaitingOrder_DTO) });

}

@section featured {
<section class="featured">
    <div class="content-wrapper">
        <hgroup class="title">
            <h1>@Page.Title .</h1>< br/>
            <h2>Content of the MSMQ</h2>
        </hgroup>
        <p>This table will show you the content of the MicroSoft Message Queuing used for COT Follow Up.</p>
        <p>
           <!-- ADD THINGS HERE -->
            @errorMessage
            <table border="1">
                <tr>
                    <td>COT ID</td>
                    <td>Row ID</td>
                    <td>Number of attempts</td>
                    <td>Next attempt at</td>
                    <td>Cot Message</td>
                    <td>Status</td>
                    <td>Success</td>
                </tr>
                @foreach (var msg in msgs)
                {
                    myqueue.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(AwaitingOrder_DTO) });
                    var message = (AwaitingOrder_DTO)msg.Body;
                    <tr>
                        <td>@message.COTID</td>
                        <td>@message.rowId</td>
                        <td>@message.numberOfRetries</td>
                        <td>@message.nextAttempt</td>
                        <td>@message.cotMessage</td>
                        <td>@message.status</td>
                        <td>@message.success</td>
                    </tr>
                }
            </table>
        </p>
    </div>
</section>
}

The code is a copy pasta from one server to the other, and the deployment was done exactly in the same way. Would anyone know what I can look at to correct this?

I've searched for solutions but : I have a formatter, so it doesn't seem to be the problem. The code works on another server, so I guess it might be unrelated to the code itself but to environment. I've checked with "go to definition" where the page got "awaiting order dto" and "queue writer" definition from, and it sends me to a "from metadata" page which makes me wonder if that might be the trouble, but I highly doubt that, since even if the queue writer isn't in the direct metadata, the page is able to send messages to the msmq, just not to read it's content.

Any idea?

(Sorry for long post)

DoctorPrisme
  • 103
  • 2
  • 11
  • It sounds very much to me like there are messages on your production server that are not of the structure you are expecting, is there any way you can check this? – Justin Harvey Oct 06 '16 at 08:44
  • That queue is only used by one program, and there's nothing else in the queue. I've done a few tests, since the page is also able to create a minimal message and send it to the msmq, and the messages are correctly sent, but as soon as the queue isn't empty, poof. – DoctorPrisme Oct 06 '16 at 08:49
  • http://stackoverflow.com/questions/655276/message-queue-error-cannot-find-a-formatter-capable-of-reading-message ? – brijber Oct 06 '16 at 09:10
  • brijber : No, I looked at this, but it didn't solve my trouble, for two reasons: --I do have a formatter, which is even in the quoted code here above. --The code works on another platform, meaning my problem probably comes from environment. – DoctorPrisme Oct 06 '16 at 09:14

1 Answers1

0

So, I've found the origin of my problems:

--As stated, the f12/see definition option showed me metadata, but I didn't find any real class/code corresponding. ==> This led me to search information about where you put the code in asp.net web app. Answer is : in "app code folder", which is then compiled to make "app code dll". Guess what? You can't just copy paste that file and hope it'll work, apparently.

So I re-took source code, re-compiled, and replaced the "failing" files. Tadaaa, I can monitor my msmq.

(Also had a typo to correct because the page failed to create correct DTO for the transfer, and had to clean the queue multiple times since it's in prod and I can't simply send wrong informations but hey. That's how you learn).

At least now I'm registered on SO.

DoctorPrisme
  • 103
  • 2
  • 11