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

Horrible bug in VS.net 2003 - please confirm

Please, someone verify that this isn't just my system with this error...
The problem is that VS.net can't properly store large 'long' values for
control properties.. I'm guessing the threshold is actually if they are
larger than an int.MaxValue.

Steps to reproduce:

1. Create a Windows Control Library project
2. Create a new control
3. Add a 'protected long' member
4. Add a 'public long' get/set accessor for the member (make the get
return the value, and the set assign the value to the member)
5. Create a Windows Forms project (then build the solution)
6. Add the control to the form
7. Set the property on the control to a large long value
8. Run (ok everything works fine)
9. When you view the properties of the control, the value isn't preserved
properly.

The large long value I use is 632890064081923187. This is actually the
DateTime.UtcNow.Ticks value for my system. Although I am writing the
control to be used with DateTime's, I also want to be able to use it for
any long value, not just DateTimes. I say this because I have a feeling
that this problem doesn't manifest itself if I use DateTimes.

You can kind of see what might be happening in the InitializeComponent
class of the windows form... on my system it generates the code:

this.control1.LongValue = ((long)(632890064081923187));

Now I'm not 100% sure, but it seems to me that the numeric value might be
being interpreted as an int before it gets cast to a long.

FYI I haven't tried this with VS 2005, but it doesn't matter because I need
to use VS 2003.

Can anyone confirm that this isn't just my system? Does anyone know of a
fix for this?

Thanks!

-mdb
Jul 20 '06 #1
14 1223
Michael Bray <mbray@makedintodot_ctiusadcomwrote:
>
this.control1.LongValue = ((long)(632890064081923187));
What about:

this.control1.LongValue = 632890064081923187L;
--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

Jul 20 '06 #2
Trivial and ineffective. I don't want to have to set this in my
constructor or something... and making this change in the
InitializeComponent will only be overwritten when I make any changes.
Maybe even when I recompile. Remember the code I'm talking about is the
auto-generated code made by VS.net.

-mdb

"Thomas T. Veldhouse" <ve*****@yahoo.comwrote in
news:rJ******************************@giganews.com :
Michael Bray <mbray@makedintodot_ctiusadcomwrote:
>>
this.control1.LongValue = ((long)(632890064081923187));

What about:

this.control1.LongValue = 632890064081923187L;
Jul 20 '06 #3
Michael Bray <mbray@makedintodot_ctiusadcomwrote:
Trivial and ineffective. I don't want to have to set this in my
constructor or something... and making this change in the
InitializeComponent will only be overwritten when I make any changes.
Maybe even when I recompile. Remember the code I'm talking about is the
auto-generated code made by VS.net.
What? I am indicating your syntax was wrong:

use:

this.control1.LongValue = 632890064081923187L;

instead of:

this.control1.LongValue = ((long)(632890064081923187));

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

Jul 20 '06 #4
Michael Bray <mbray@makedintodot_ctiusadcomwrote:
Trivial and ineffective. I don't want to have to set this in my
constructor or something... and making this change in the
InitializeComponent will only be overwritten when I make any changes.
Maybe even when I recompile. Remember the code I'm talking about is the
auto-generated code made by VS.net.
Ignore my last post, I didn't realize your long value is actually your system
clock ticks.

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

Jul 20 '06 #5
I'll ignore it, but not because it's system clock ticks. I'll ignore it
because I didn't write that code - it is auto-generated by VS.net. :)

-mdb

"Thomas T. Veldhouse" <ve*****@yahoo.comwrote in
news:L6******************************@giganews.com :
Michael Bray <mbray@makedintodot_ctiusadcomwrote:
>Trivial and ineffective. I don't want to have to set this in my
constructor or something... and making this change in the
InitializeComponent will only be overwritten when I make any changes.
Maybe even when I recompile. Remember the code I'm talking about is
the auto-generated code made by VS.net.

Ignore my last post, I didn't realize your long value is actually your
system clock ticks.
Jul 20 '06 #6

Michael Bray wrote:
Please, someone verify that this isn't just my system with this error...
The problem is that VS.net can't properly store large 'long' values for
control properties.. I'm guessing the threshold is actually if they are
larger than an int.MaxValue.
<snip>
You can kind of see what might be happening in the InitializeComponent
class of the windows form... on my system it generates the code:

this.control1.LongValue = ((long)(632890064081923187));

Now I'm not 100% sure, but it seems to me that the numeric value might be
being interpreted as an int before it gets cast to a long.
Always test before posting! <Evil grin>

I tried exactly what you suggested, and my VS2003 Designer generates
exactly the same code.

However, I also dropped a TextBox on my UserControl and had it display
the contents of the private field; the text box showed
632890064081923187, exactly as it should have.

I'll leave it to someone who understands the dark interior workings of
C# to explain why the above code results in a long literal, not an int
literal. Nonetheless, it appears to cause no problems: everything works
out the way you would expect (expect at the macro level, that is).

Jul 20 '06 #7
Michael Bray <mbray@makedintodot_ctiusadcomwrote:
I'll ignore it, but not because it's system clock ticks. I'll ignore it
because I didn't write that code - it is auto-generated by VS.net. :)
In which case I would report it and indicate its "horribleness" when you do
;-)

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

Jul 20 '06 #8
"Bruce Wood" <br*******@canada.comwrote in
news:11**********************@m79g2000cwm.googlegr oups.com:
Always test before posting! <Evil grin>

I tried exactly what you suggested, and my VS2003 Designer generates
exactly the same code.

However, I also dropped a TextBox on my UserControl and had it display
the contents of the private field; the text box showed
632890064081923187, exactly as it should have.

I'll leave it to someone who understands the dark interior workings of
C# to explain why the above code results in a long literal, not an int
literal. Nonetheless, it appears to cause no problems: everything
works out the way you would expect (expect at the macro level, that
is).

Oh man I've been testing for hours... I see the problem every time. Let
me give more details...

On my usercontrol, I paint the value in the OnPaint. Sometimes, even
though the 'bad' value shows up in the designer where the control is on the
form, when I run the form it shows the correct value.

But then, if I change some things around in the control, such as the
location or size of the control, then the value sticks to the bad value and
that's what I see when I run the form.

The critical part for me is that after I've dropped the control on the
form, and then I run the program (and the control paints the correct
value), when I look at the value in the designer next, it has the 'bad'
value. Did you look at the designer value or just the value in the
textBox? Did you play with the control at all? I would guess that if you
play for a bit then it will show.

I'll even make a video of it happening and I can show you... I'll post code
even. I'll make another post when they are ready.

-mdb
Jul 20 '06 #9
Michael Bray <mbray@makeDIntoDot_ctiusaDcomwrote in
news:Xn****************************@207.46.248.16:
I'll even make a video of it happening and I can show you... I'll post
code even. I'll make another post when they are ready.
OK... I made a screen-cap movie of what's happening. You can download the
movie (22MB) and the source code (a few K) with the following links:

http://users.ctinet.net/mbray/BadControlMovie.zip
http://users.ctinet.net/mbray/DumbTest.zip

Extract DumbTest.zip to a directory, and open the solution file in DumbTest
subFolder. Use the movie to see exactly what I am doing.

-mdb
Jul 20 '06 #10
Michael Bray <mbray@makedintodot_ctiusadcomwrote:
Michael Bray <mbray@makeDIntoDot_ctiusaDcomwrote in
news:Xn****************************@207.46.248.16:
>I'll even make a video of it happening and I can show you... I'll post
code even. I'll make another post when they are ready.

OK... I made a screen-cap movie of what's happening. You can download the
movie (22MB) and the source code (a few K) with the following links:

http://users.ctinet.net/mbray/BadControlMovie.zip
http://users.ctinet.net/mbray/DumbTest.zip

Extract DumbTest.zip to a directory, and open the solution file in DumbTest
subFolder. Use the movie to see exactly what I am doing.
Your movie was too big to download. However, I was able to download your code
and set the value [via the properties panel] to 632890064081923187. That
number is beyond the range of a Int32 variable and within the range of a Int64
variable, signed in both cases. long is an Int64 (signed) for all intents and
purposes. It worked just fine .... every time. It is mysterious to me why it
is not casting too an int first though, as it really should be without the
literal declaration of the L.

In short, I didn't see any issues at all.

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

Jul 20 '06 #11
OK I just tried this on a colleagues machine, and I see the exact same
problem. It can't be just me. Maybe it is our particular version of
VS.NET 2003?

-mdb

"Bruce Wood" <br*******@canada.comwrote in
news:11**********************@m79g2000cwm.googlegr oups.com:
>
Michael Bray wrote:
>Please, someone verify that this isn't just my system with this
error... The problem is that VS.net can't properly store large 'long'
values for control properties.. I'm guessing the threshold is
actually if they are larger than an int.MaxValue.
Jul 20 '06 #12
Michael Bray <mbray@makedintodot_ctiusadcomwrote:
OK I just tried this on a colleagues machine, and I see the exact same
problem. It can't be just me. Maybe it is our particular version of
VS.NET 2003?
MDE 2003: Version 7.1.3088
..NET Framework: Version 1.1.4322 SP1
-mdb

"Bruce Wood" <br*******@canada.comwrote in
news:11**********************@m79g2000cwm.googlegr oups.com:
>>
Michael Bray wrote:
>>Please, someone verify that this isn't just my system with this
error... The problem is that VS.net can't properly store large 'long'
values for control properties.. I'm guessing the threshold is
actually if they are larger than an int.MaxValue.
--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

Jul 20 '06 #13
MDE 2003: Version 7.1.3088
.NET Framework: Version 1.1.4322 SP1
Nope I've got the same.... OK I guess I'll just open a case w/ Microsoft.

Thanks for checking...

-mdb
Jul 20 '06 #14
Looks like a bug to me.
It happens on my copy of VS2003.

There's actually no difference between
long value = (long)632890064081923187;
and
long value = 632890064081923187L;
The compiler will recognise the first pattern and treat it as a long
literal.

(Hence doing it the other way round:
int value = (int) (632890064081923187L)
is a compiler error even though it looks like a valid, if unchecked,
cast from long to int).

The designer probably chose to do it that way as it works with all
primitive types (there isn't a literal syntax for all types AFAIK).

The problem seems to occour when the designer reloads the file, e.g.
when you compile.
i.e. when it's reading back the designer generated code (it does this
so it can update to any changes you may have made in the designer
generated code by hand - and when it's only got that code to work from
such as when you first open the file). It reads the value back wrong,
probably treating the code "(long)632890064081923187" literally as a
cast from an int literal to a long value. It then puts this bad value
into the property sheet, but doesn't change the code at that point. The
next time you save however the bad value will get written out as it
rewrites the designer generated code.

Doesn't seem to happen with VS 2005 though.

Terry
Michael Bray wrote:
Michael Bray <mbray@makeDIntoDot_ctiusaDcomwrote in
news:Xn****************************@207.46.248.16:
I'll even make a video of it happening and I can show you... I'll post
code even. I'll make another post when they are ready.

OK... I made a screen-cap movie of what's happening. You can download the
movie (22MB) and the source code (a few K) with the following links:

http://users.ctinet.net/mbray/BadControlMovie.zip
http://users.ctinet.net/mbray/DumbTest.zip

Extract DumbTest.zip to a directory, and open the solution file in DumbTest
subFolder. Use the movie to see exactly what I am doing.

-mdb
Jul 20 '06 #15

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

Similar topics

140
by: Oliver Brausch | last post by:
Hello, have you ever heard about this MS-visual c compiler bug? look at the small prog: static int x=0; int bit32() { return ++x; }
9
by: Marc Miller | last post by:
Hi all, I have 2 dev. machines, the 1st is Win 2000 with .NET 7.0 and the 2nd is XP Pro with .NET 2003. My Web Server is Win 2000 Server with IIS 5.0. I can create a new project on my test...
2
by: Praveen | last post by:
Hi All, I have made a webservice in C# and it works fine in my machine. I ran into a crazy problem when I wanted to deploy it in windows 2003 server. I have run "aspnet_regiis.exe -i" to make...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.