473,397 Members | 1,985 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,397 software developers and data experts.

How is this possible

I was getting a "Specified cast is not valid" error when sending to a MSMQ. This happens very occasionally and so cannot reproduce to debug. So I modified my function as shown below.
sb is a private stringbuilder within that class and is not modified by any threads or other processes at same time. Bytes from a network stream are appended to it and then this function is called. Line and Len variables were added just to find the error.

private void ProcessDataReceived()
{
int Line = 0, Len = 0;
string data = "";
try
{
Line++;
if ( sb.Length > 0 )
{
Line++; data = sb.ToString() ;
Len = sb.Length;
Line++; sb.Length = 0 ; // Clear buffer
Line++; Controller.MSMQ.Send(data);
}
}
catch(Exception E)
{
if(sb == null)
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>sb is null");
else if(data == null)
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>data is null");
else
{
if(data.Length > 0) //to see if any wacky characters from Network
{
string s = "";
foreach(char c in data)
{
s += System.Convert.ToInt32(c).ToString() + "**";
}
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>" + Controller.MSMQ.Path + "<BR>sb Len=" + Len.ToString() + "<BR>data =" + s );
}
else
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>" + Controller.MSMQ.Path + "<BR>sb Len=" + Len.ToString() + "<BR>data =" + data);
}
}
}

Here is the error I got emailed

Specified cast is not valid.
Line#: 4
..\Private$\WebTechGPS
sb Len=0
data =

I cannot figure out how this is possible. Line#: 4 implies it went into the if clause and the error was caused by MSMQ.Send. How can Len value be 0 ?
Sorry for the HTML format. Its easy to highlight this way.

Any suggestions appreciated. I am clueless.

Thanks

Srinivas Loka

Nov 17 '05 #1
3 1330
"SRLoka" <ls******@hotmail.com> wrote in message news:Ob**************@TK2MSFTNGP15.phx.gbl...
I was getting a "Specified cast is not valid" error when sending to a MSMQ. This happens very occasionally and so cannot reproduce to debug. So I modified my function as shown below.
sb is a private stringbuilder within that class and is not modified by any threads or other processes at same time. Bytes from a network stream are appended to it and then this function is called. Line and Len variables were added just to find the error.

private void ProcessDataReceived()
{
int Line = 0, Len = 0;
string data = "";
try
{
Line++;
if ( sb.Length > 0 )
{
Line++; data = sb.ToString() ;
Len = sb.Length;
Line++; sb.Length = 0 ; // Clear buffer
Line++; Controller.MSMQ.Send(data);
}
}
catch(Exception E)
{
if(sb == null)
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>sb is null");
else if(data == null)
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>data is null");
else
{
if(data.Length > 0) //to see if any wacky characters from Network
{
string s = "";
foreach(char c in data)
{
s += System.Convert.ToInt32(c).ToString() + "**";
}
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>" + Controller.MSMQ.Path + "<BR>sb Len=" + Len.ToString() + "<BR>data =" + s );
}
else
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>" + Controller.MSMQ.Path + "<BR>sb Len=" + Len.ToString() + "<BR>data =" + data);
}
}
}

Here is the error I got emailed

Specified cast is not valid.
Line#: 4
.\Private$\WebTechGPS
sb Len=0
data =

I cannot figure out how this is possible. Line#: 4 implies it went into the if clause and the error was caused by MSMQ.Send. How can Len value be 0 ?
Sorry for the HTML format. Its easy to highlight this way.

Any suggestions appreciated. I am clueless.

Thanks

Srinivas Loka

Nov 17 '05 #2
Sorry for the previous empty post. I pressed the wrong key. GRRR.
Why not set a breakpoint in the exception handler? When you hit it, move the execution point back up again and re-execute the Send().

-- Alan
"SRLoka" <ls******@hotmail.com> wrote in message news:Ob**************@TK2MSFTNGP15.phx.gbl...
I was getting a "Specified cast is not valid" error when sending to a MSMQ. This happens very occasionally and so cannot reproduce to debug. So I modified my function as shown below.
sb is a private stringbuilder within that class and is not modified by any threads or other processes at same time. Bytes from a network stream are appended to it and then this function is called. Line and Len variables were added just to find the error.

private void ProcessDataReceived()
{
int Line = 0, Len = 0;
string data = "";
try
{
Line++;
if ( sb.Length > 0 )
{
Line++; data = sb.ToString() ;
Len = sb.Length;
Line++; sb.Length = 0 ; // Clear buffer
Line++; Controller.MSMQ.Send(data);
}
}
catch(Exception E)
{
if(sb == null)
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>sb is null");
else if(data == null)
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>data is null");
else
{
if(data.Length > 0) //to see if any wacky characters from Network
{
string s = "";
foreach(char c in data)
{
s += System.Convert.ToInt32(c).ToString() + "**";
}
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>" + Controller.MSMQ.Path + "<BR>sb Len=" + Len.ToString() + "<BR>data =" + s );
}
else
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>" + Controller.MSMQ.Path + "<BR>sb Len=" + Len.ToString() + "<BR>data =" + data);
}
}
}

Here is the error I got emailed

Specified cast is not valid.
Line#: 4
.\Private$\WebTechGPS
sb Len=0
data =

I cannot figure out how this is possible. Line#: 4 implies it went into the if clause and the error was caused by MSMQ.Send. How can Len value be 0 ?
Sorry for the HTML format. Its easy to highlight this way.

Any suggestions appreciated. I am clueless.

Thanks

Srinivas Loka

Nov 17 '05 #3
The problem is, there is no way no to know when the error will occur. I just get one or two errors a week. The process runs 24/7 and handles 1000s of messages a day. So I cannot debug. I do not know what is causing the error and the unexplainable behavior.

Thanks
"Alan Pretre" <al********@newsgroup.nospam> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Sorry for the previous empty post. I pressed the wrong key. GRRR.
Why not set a breakpoint in the exception handler? When you hit it, move the execution point back up again and re-execute the Send().

-- Alan
"SRLoka" <ls******@hotmail.com> wrote in message news:Ob**************@TK2MSFTNGP15.phx.gbl...
I was getting a "Specified cast is not valid" error when sending to a MSMQ. This happens very occasionally and so cannot reproduce to debug. So I modified my function as shown below.
sb is a private stringbuilder within that class and is not modified by any threads or other processes at same time. Bytes from a network stream are appended to it and then this function is called. Line and Len variables were added just to find the error.

private void ProcessDataReceived()
{
int Line = 0, Len = 0;
string data = "";
try
{
Line++;
if ( sb.Length > 0 )
{
Line++; data = sb.ToString() ;
Len = sb.Length;
Line++; sb.Length = 0 ; // Clear buffer
Line++; Controller.MSMQ.Send(data);
}
}
catch(Exception E)
{
if(sb == null)
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>sb is null");
else if(data == null)
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>data is null");
else
{
if(data.Length > 0) //to see if any wacky characters from Network
{
string s = "";
foreach(char c in data)
{
s += System.Convert.ToInt32(c).ToString() + "**";
}
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>" + Controller.MSMQ.Path + "<BR>sb Len=" + Len.ToString() + "<BR>data =" + s );
}
else
EMailErr("MSMQ Send Error",E.Message.ToString() + "<BR>Line#: " + Line.ToString() + "<BR>" + Controller.MSMQ.Path + "<BR>sb Len=" + Len.ToString() + "<BR>data =" + data);
}
}
}

Here is the error I got emailed

Specified cast is not valid.
Line#: 4
.\Private$\WebTechGPS
sb Len=0
data =

I cannot figure out how this is possible. Line#: 4 implies it went into the if clause and the error was caused by MSMQ.Send. How can Len value be 0 ?
Sorry for the HTML format. Its easy to highlight this way.

Any suggestions appreciated. I am clueless.

Thanks

Srinivas Loka

Nov 17 '05 #4

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

Similar topics

1
by: Alvin Lau | last post by:
It is possible to write a bluetooth application software by C# in Pocket PC ? If it is possible , where can i find the reference or sample? ThX ~ *** Sent via Developersdex...
1
by: Lars | last post by:
I want to write a program that reacts on changes in another application. Is it possible to get a copy of (some of) the messages it recieves? Another approach is to watch for changes on the screen....
4
by: Ravikanth[MVP] | last post by:
Hi It is possible that IIS and SQL Server can reside on Seperate Machines and you can use Integrated Windows Authentication to connect. Ravikanth >-----Original Message-----
9
by: sumit1680 | last post by:
Hi all, recently i tried the following peice of code in gcc int main () { char *ptr = "possible"; printf("%s",ptr); return (0); }
8
by: Mir Nazim | last post by:
Hello, I need to write scripts in which I need to generate all posible unique combinations of an integer list. Lists are a minimum 12 elements in size with very large number of possible...
17
by: binjobster | last post by:
Hello everyone, I'm updating some documents that describes so many C/C++ functions/method(about 2500). But I'm not familiar with these codes. So I want to find such a utility can generate...
1
by: Joe Peterson | last post by:
I've been doing a lot of searching on the topic of one of Python's more disturbing issues (at least to me): the fact that if a __del__ finalizer is defined and a cyclic (circular) reference is...
25
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e....
2
by: Kofa | last post by:
Dear All, I'd like to know whether it is possible to restore backups created on a production machine, running DB2 9.1 on Windows, using DMS table space containers, onto a developer's machine,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.