473,324 Members | 2,511 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,324 software developers and data experts.

Very bizzare code behaviour.

G'Day,

I have a simple peice of code behaving in a rather eratic manner.

outputStreams[(int)service] = new MemoryStream();
//.... some code to add values to the stream ...
bool ready = false;
//.... some code...
ready = (outputStreams[(int)service].Length > 0);

The last line of code is giving me extrodanary grivance so I put a
breakpoint on it.
When inspected at this breakpoint "outputStreams[(int)service].Length"
equates to 45.
Yet after the statement completes "ready" remains false.

"outputStreams" does not have anything else using it's name in a
different scope so the watch is definatly inspecting the variable in
the statement.

"ready" does not have anything else using it's name in a different
scope so the assignment is definatly inspecting the variable in the
statement. Yes ready is a local variable.

I can only think of two unlikely scenarios to explain this problem I am
facing.
1) The ">" operator does not like to compare a long value with the
expession "0".
2) The watch is given a eronious value when it reads the poperty
outputStreams[(int)service].Length and the code revices a another value
when calling the property.

Well if either of those two possibilites were true id be rather
suprissed.

Anyway for the paraniod I include a dump of the watch in question.

I just find this particular problem so bizzare I thought I'd share it.

-dm
- outputStreams[(int)service] {System.IO.MemoryStream} System.IO.MemoryStream
- System.IO.Stream {System.IO.MemoryStream} System.IO.Stream
+ System.MarshalByRefObject {System.IO.MemoryStream} System.MarshalByRefObject
CanRead true bool
CanSeek true bool
CanWrite true bool
Length 45 long
+ Null {System.IO.Stream.NullStream} System.IO.Stream
Position 45 long
+ _buffer {Length=256} byte[]
_capacity 256 int
_expandable true bool
_exposable true bool
_isOpen true bool
_length 45 int
_origin 0 int
_position 45 int
_writable true bool
CanRead true bool
CanSeek true bool
CanWrite true bool
Capacity 256 int
Length 45 long
MemStreamMaxLength 2147483647 int
Position 45 long

Apr 6 '06 #1
2 1546
I just simplifiedied a bit to isolate the problem, I added this
statement.

long foobar = outputStreams[(int)service].Length;

Looking at watches before this new statement
foobar = undefined
outputStreams[(int)service].Length = 45

Looking at watches after this new statement
foobar = 0
outputStreams[(int)service].Length = 45

It's official I've broken my watch!

My dev enviroment is visual studio 2003. My os is winXP prof and I am
developing with full administarative privilages.

Anybodey seen this before. ever?

My best guess if that the get accesor code for "MemoryStream.Length "
does some sort of security check and returns 0 if the calling code
doesn't meat some condition.

In this whay the debuger might have sufficent privliges and my own code
(which created the streams) has lost privliges.

This guess is afdmitably very unlikely,

Smobody got a better Idea?

-dm

Apr 6 '06 #2


th*********@gmail.com wrote:
I just simplifiedied a bit to isolate the problem, I added this
statement.
You can make it even more debug-friendly:

int index = (int)service;
Stream outstream = outputStreams[index];
long len = outstream.Length;

Here you can verify each of the crucial assumptions:

- Is the code indexing right?
- Is the indexed stream correct?
Anybodey seen this before. ever?
I have seen something like it, it was due to a watch-expression mutating
the state by invoking a method -- be sure that's not what's hapeening to
you. You don't have a property that clears the stream and returns it's
former length, do you?

If your bug remains, reduce the amount of code running .. effectively
try and end up with something like:

public static int Main() {
MemoryStream m = new MemoryStream();
m.Write('xxx');
int len = m.Length;
}

which still produces your problem.
My best guess if that the get accesor code for "MemoryStream.Length "
does some sort of security check and returns 0 if the calling code
doesn't meat some condition.
That's not what's happening.
This guess is afdmitably very unlikely,


yes ;)

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Apr 6 '06 #3

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

Similar topics

18
by: Richard Gutery | last post by:
I have an ASP page that I need to have a Message Box on. When I try to run the page, I get the following message : Exception Not Handled. Permission Denied. To trouble shoot, I gave everyone...
8
by: BCC | last post by:
I am getting a non-reproduceable release mode only error, that is proving to be really a pain. I can in some cases narrow it down by try/catch blocks but even that behavior is totally f*ed up. ...
1
by: Zri Man | last post by:
I have come across a bizzare behaviour with DB2/UDB 8.2 on SuSE Linux 2.41 When I have a MQT Refresh going on (complete refresh) it appears to lock the underlying base tables used to build the...
8
by: Robert Gravereaux | last post by:
I've noticed that the first exception thrown/caught by an app running in debug is very slow - it takes perhaps 7 or 8 seconds on my P4 machine. I've noticed this on several different machines...
7
by: Martin Pritchard | last post by:
Hi, Sorry for my ignorance, but I'm a bit new to C++. I've been handed over a C++ app written in VS2002 which I have to convert to VS2005. Apparently it's been written in a C style, but cannot...
5
by: Johs32 | last post by:
I have the follwing code: #include <stdio.h> #include <stdlib.h> struct data { int *ip; };
126
by: jacob navia | last post by:
Buffer overflows are a fact of life, and, more specifically, a fact of C. All is not lost however. In the book "Value Range Analysis of C programs" Axel Simon tries to establish a...
4
by: jlhsgcib | last post by:
Hello, I have the following snippet of code: sub getPasswordStatus { my ($login, $password) = @_; my$quotedLogin = quotemeta($login);
11
Dormilich
by: Dormilich | last post by:
recently I encounter a very strange behaviour of the session variable. if the cookies are disabled, the session id is totally misplaced (see code). instead being attached to the URL it is placed...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.