473,396 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

MSMQ - Specified cast is not valid Error

I have an application that has five threads. All five threads write to the
same MSMQ. All five threads are using the same global instance to send data
to the MSMQ server(on same machine).
Occasionally, I get the erroror below. The data(string) being sent is not
null or empty. Is this a problem related to multiple threads ? Right now I
have coded it like this

Controller.MSMQ.Send(Record);

Should I change to

lock(Controller.MSMQ)
{
Controller.MSMQ.Send(Record);
}

Thanks.
Below is the actual error

Specified cast is not valid.
P R O P E R T I E S
------------------
Message: Specified cast is not valid.
InnerException:
TargetSite: MQPROPS Lock()
StackTrace: at System.Messaging.Interop.MessagePropertyVariants.L ock()
at System.Messaging.Message.Lock()
at System.Messaging.MessageQueue.SendInternal(Object obj,
MessageQueueTransaction internalTransaction, MessageQueueTransactionType
transactionType)
at System.Messaging.MessageQueue.Send(Object obj)
at TCPServer.CH.Process(String ThreadName)
HelpLink:
Source: System.Messaging
Nov 17 '05 #1
4 5734
Or should I use a separate instance for each thread ?
(Always too quick to hit that send)

Thanks
Nov 17 '05 #2
SRLoka,

I would definitely create a separate instance for each thread that you
are using. The documentation for the class states that the following
methods are thread-safe:

BeginPeek, BeginReceive, EndPeek, EndReceive, GetAllMessages, and Peek,
Receive.

Unfortunately, you are using the Send message, which is not thread-safe.
I would start with using separate instances on each thread.

Also, what formatter are you using to send the message? I ask only
because some formatters require the type to be serializable.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SRLoka" <ls******@hotmail.com> wrote in message
news:uY**************@TK2MSFTNGP15.phx.gbl...
Or should I use a separate instance for each thread ?
(Always too quick to hit that send)

Thanks

Nov 17 '05 #3
Thanks Nicholas. The Record variable is just a string.
Would it be OK to use a Lock
lock(MSMQ)
{
MSMQ.Send
}
instead of a separate queue opened for each thread ?
Will a separate queue for each thread be more efficient. ? Looks like it
based on the docs on MSDN. I will try the lock first(easy way out) and then
code for the separate queue.

Thanks

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oo****************@TK2MSFTNGP09.phx.gbl...
SRLoka,

I would definitely create a separate instance for each thread that you
are using. The documentation for the class states that the following
methods are thread-safe:

BeginPeek, BeginReceive, EndPeek, EndReceive, GetAllMessages, and Peek,
Receive.

Unfortunately, you are using the Send message, which is not
thread-safe. I would start with using separate instances on each thread.

Also, what formatter are you using to send the message? I ask only
because some formatters require the type to be serializable.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SRLoka" <ls******@hotmail.com> wrote in message
news:uY**************@TK2MSFTNGP15.phx.gbl...
Or should I use a separate instance for each thread ?
(Always too quick to hit that send)

Thanks


Nov 17 '05 #4
I would use a separate instance on each thread. After all, the MSMQ
subsystem knows how to handle messages coming in on different threads.
There is no need for you to try and second-guess it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SRLoka" <ls******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Thanks Nicholas. The Record variable is just a string.
Would it be OK to use a Lock
lock(MSMQ)
{
MSMQ.Send
}
instead of a separate queue opened for each thread ?
Will a separate queue for each thread be more efficient. ? Looks like it
based on the docs on MSDN. I will try the lock first(easy way out) and
then code for the separate queue.

Thanks

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Oo****************@TK2MSFTNGP09.phx.gbl...
SRLoka,

I would definitely create a separate instance for each thread that you
are using. The documentation for the class states that the following
methods are thread-safe:

BeginPeek, BeginReceive, EndPeek, EndReceive, GetAllMessages, and Peek,
Receive.

Unfortunately, you are using the Send message, which is not
thread-safe. I would start with using separate instances on each thread.

Also, what formatter are you using to send the message? I ask only
because some formatters require the type to be serializable.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SRLoka" <ls******@hotmail.com> wrote in message
news:uY**************@TK2MSFTNGP15.phx.gbl...
Or should I use a separate instance for each thread ?
(Always too quick to hit that send)

Thanks



Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception:...
4
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
3
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my...
2
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: ...
3
by: VB Programmer | last post by:
I am setting up forms authentication. In my code I keep getting this error. Any ideas? Error.... Server Error in '/LandOLots' Application....
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
0
by: Alan Z. Scharf | last post by:
this question in datagrid group for several days with no repsonse. I'm hoping for an answer her because of greater activity in this group. No cross-posting intended. Thanks....
2
by: Kashiefah | last post by:
Hi, I keep on receiving this error when I click on the edit email link from the datagrid:Specified cast is not valid. Description: An unhandled exception occurred during the execution of the...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.