InvalidCastException from IBM-MQ COM component when running in thr

G

Guest

I have just started using VB.Net and I am developing a class to provide data
to clients from an IBM-MQ queue.

I have developed a class which connects to the queue and issues a read. When
a message comes in an event is raised back to the client containing (at the
moment) only the message id.

This all works fine but the MQ read call blocks and prevents other processing.

To overcome this I have created the object and then start the listening in a
thread. The MQ session object is created but then the first call to any
property on that object causes and InvalidCastException to the be thrown from
within QueryInterface.

Any advice much appreciated.
 
C

Cor Ligthert [MVP]

Geoff,

Start with setting Option Strict On in top of your program.

Than you are not using late binding, what means that it is showed in your
code where those errors can be.

I hope this helps,

Cor
 
G

Guest

Cor

Thanks for the suggestion. I do have Option Strict On at the start of the
code.

The code works fine when the class is run in the main thread, it is only
when I try and run it in a thread of its own using.

Dim thrd As Thread
thrd = New Thread(New ThreadStart(AddressOf myQueue.StartListening))
thrd.Start()

Regards
Geoff
 
C

Cor Ligthert [MVP]

Geoff,

I have the idea that I use somewhere a thread as well very much recursive,
however, is that queue method a queue method that change the queue and
therefore needs a synclock.

It is just a gues

Cor
 
G

Guest

A bit more info.

The exception is coming as it appears it cannot find the IMQSession200
interface in the IBM-MQ ActiveX component.

I have looked in the object browser and the interface is shown as Public
when 'Show Hidden Member' is selected.
 
G

Guest

Cor

Thanks for that, I'll have a look at locking. It's the next thing in the
chapter of the book I'm reading now :)

I've trawled the net a bit more and there are other documented issues with
using the IBM-MQ ActiveX control within a .Net thread, so it may be that I'm
trying to do something that is limited by the control.

I've looked at the different threading models (MTA,STA) for the thread and
played about with those to no joy.

I've hacked the code about so that it runs in a thread but doesn't make use
of MQ (pointless class but to prove it wasn't my misunderstanding of threads)
and all works fine.

There certainly seems to be some problem when trying to instantiate an
MQSession object. I did read in the docs that theInvalidCastException error
can be thrown by mscorlib when failing to access an interface in a COM
component. I believe that this is where the problem lies.

Regards
Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top