Erroneous Error Cannot create an array with a negative size

O

ozbear

Using :
Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
Microsoft .NET Framework
Version 3.5 SP1
Installed Edition: Professional
Microsoft Visual C# 2008

The IDE displays the error Cannot create an array with
a negative size whenever the source is modified but the
project does build and the error goes away, until modified
again:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ArrayBug
{
public partial class Form1 : Form
{

const int N = 4096; /* buffer size */
const int F = 60; /* lookahead buffer size */
byte[] text_buf = new byte[(N + F) - 1];
public Form1()
{
InitializeComponent();
}
}
}

The error appears in the IDE at the text_buf declaration.
The project does build, however, and the array size at
runtime is correct. I have searched for other reports of
this and have not found anything.

Oz
 
P

Peter Duniho

ozbear said:
[...]
namespace ArrayBug
{
public partial class Form1 : Form
{

const int N = 4096; /* buffer size */
const int F = 60; /* lookahead buffer size */
byte[] text_buf = new byte[(N + F) - 1];
public Form1()
{
InitializeComponent();
}
}
}

The error appears in the IDE at the text_buf declaration.
The project does build, however, and the array size at
runtime is correct. I have searched for other reports of
this and have not found anything.

For what it's worth, your code example could have been far simpler. I
can get the problem to happen in the simplest class. No need for a
Forms application.

Have you tried to reproduce in the VS2010 beta? I don't have it
installed, but if you care about the problem you should check it there.
There may still be time to get it fixed, if it's a simple fix and it
hasn't already been corrected.

It looks like the IDE is failing to correctly interpret the constants,
and thinks that all you've got is "-1" as the size. You may already
have noticed, but there's no error message if you put the calculation in
a third constant and then just use the constant for the declaration.

Pete
 
F

Family Tree Mike

ozbear said:
[...]
namespace ArrayBug
{
public partial class Form1 : Form
{

const int N = 4096; /* buffer size */
const int F = 60; /* lookahead buffer size */
byte[] text_buf = new byte[(N + F) - 1]; public Form1()
{
InitializeComponent();
}
}
}

The error appears in the IDE at the text_buf declaration.
The project does build, however, and the array size at runtime is
correct. I have searched for other reports of this and have not found
anything.

For what it's worth, your code example could have been far simpler. I
can get the problem to happen in the simplest class. No need for a Forms
application.

Have you tried to reproduce in the VS2010 beta? I don't have it
installed, but if you care about the problem you should check it there.
There may still be time to get it fixed, if it's a simple fix and it
hasn't already been corrected.

It looks like the IDE is failing to correctly interpret the constants,
and thinks that all you've got is "-1" as the size. You may already have
noticed, but there's no error message if you put the calculation in a
third constant and then just use the constant for the declaration.

Pete

Interesting. I couldn't reproduce this with VS 2010 C# Beta 2, so I
left the post alone.

I went back to 2008, and now I do see it there, so it appears to be
fixed in Beta 2.
 
O

ozbear

ozbear said:
[...]
namespace ArrayBug
{
public partial class Form1 : Form
{

const int N = 4096; /* buffer size */
const int F = 60; /* lookahead buffer size */
byte[] text_buf = new byte[(N + F) - 1];
public Form1()
{
InitializeComponent();
}
}
}

The error appears in the IDE at the text_buf declaration.
The project does build, however, and the array size at
runtime is correct. I have searched for other reports of
this and have not found anything.

For what it's worth, your code example could have been far simpler. I
can get the problem to happen in the simplest class. No need for a
Forms application.

Never miss an opportunity to disapprove, do you?
The post was to provide /my/ context in which the error is displayed
in case any of the "stuff" before it was relevant.
The fact the it occurs in "the simplest class" is irrelevant.
For example, moving the three declarations to a method does not
yield the error.
Have you tried to reproduce in the VS2010 beta? I don't have it
installed, but if you care about the problem you should check it there.
There may still be time to get it fixed, if it's a simple fix and it
hasn't already been corrected.

See later post. I don't use betas, and someone else has already done
this.
It looks like the IDE is failing to correctly interpret the constants,
and thinks that all you've got is "-1" as the size. You may already
have noticed, but there's no error message if you put the calculation in
a third constant and then just use the constant for the declaration.

Pete
Yes, Captain Obvious. There are a number of things that will cause
the error to not be generated. That is what a -complete- and concise
(to use your mantra) was provided.

Oz
 
P

Peter Duniho

ozbear said:
[...]
For what it's worth, your code example could have been far simpler. I
can get the problem to happen in the simplest class. No need for a
Forms application.

Never miss an opportunity to disapprove, do you?

I was just pointing the fact out. I did not express disapproval. Once
again, you are reading far too much into what I write.
The post was to provide /my/ context in which the error is displayed
in case any of the "stuff" before it was relevant.

Unfortunately, however, you did not actually provide a complete code
example. So you didn't actually accomplish what you apparently intended
to. The entire context is not there.

In any case, it is a good habit to get into to try to reduce a problem
to the bare minimum required before asking someone else about it. That
is in fact the point of my repetitive calls for a concise-but-complete
code example. The less concise your example, the less likely anyone
will bother to look at it, and the more frustrating to anyone who does
bother.
The fact the it occurs in "the simplest class" is irrelevant.

It would certainly be relevant to anyone responsible for fixing it, as
well as for anyone else interested in seeing whether the problem is
reproducible.

People looking at bugs do not like to waste their time wading through
information that has nothing to do with the bug.
For example, moving the three declarations to a method does not
yield the error.

That doesn't relate at all to the question of how simple the class is.
[...]
It looks like the IDE is failing to correctly interpret the constants,
and thinks that all you've got is "-1" as the size. You may already
have noticed, but there's no error message if you put the calculation in
a third constant and then just use the constant for the declaration.

Pete
Yes, Captain Obvious. There are a number of things that will cause
the error to not be generated. That is what a -complete- and concise
(to use your mantra) was provided.

Except you did not provide a code example that was either complete OR
concise.

In any case, I remain boggled by your willingness to engage in ad
hominem attacks, even as you take offense at the anything that you find
remotely disagreeable. Before you worry about the speck in my eye, you
might want to get that log in yours checked out.

Pete
 
O

ozbear

ozbear said:
[...]
For what it's worth, your code example could have been far simpler. I
can get the problem to happen in the simplest class. No need for a
Forms application.

Never miss an opportunity to disapprove, do you?

I was just pointing the fact out. I did not express disapproval. Once
again, you are reading far too much into what I write.
The post was to provide /my/ context in which the error is displayed
in case any of the "stuff" before it was relevant.

Unfortunately, however, you did not actually provide a complete code
example. So you didn't actually accomplish what you apparently intended
to. The entire context is not there.

In any case, it is a good habit to get into to try to reduce a problem
to the bare minimum required before asking someone else about it. That
is in fact the point of my repetitive calls for a concise-but-complete
code example. The less concise your example, the less likely anyone
will bother to look at it, and the more frustrating to anyone who does
bother.
The fact the it occurs in "the simplest class" is irrelevant.

It would certainly be relevant to anyone responsible for fixing it, as
well as for anyone else interested in seeing whether the problem is
reproducible.

People looking at bugs do not like to waste their time wading through
information that has nothing to do with the bug.
For example, moving the three declarations to a method does not
yield the error.

That doesn't relate at all to the question of how simple the class is.
[...]
It looks like the IDE is failing to correctly interpret the constants,
and thinks that all you've got is "-1" as the size. You may already
have noticed, but there's no error message if you put the calculation in
a third constant and then just use the constant for the declaration.

Pete
Yes, Captain Obvious. There are a number of things that will cause
the error to not be generated. That is what a -complete- and concise
(to use your mantra) was provided.

Except you did not provide a code example that was either complete OR
concise.
Complete with the exception of having to create a form app and drop
the posted code in as a replacement for the IDE generated code.
10 seconds to do. Concise is in the eye of the beholder. Less than
half a page of code should fit any _reasonable_ person's definition.

Anyone whose has experienced a problem with a compiler or component
thereof (as opposed to a problem with _their_ code) knows that what
can be tripping up the compiler/IDE can be _anything_. Changing the
options in effect or merely rearranging the order can do this.
That is why it is paramount to give a reproducible example.
Merely moving the declarations from the class to local variables
within a method stops the problem from manifesting.

All that was necessary in the way of a complete and concise" *reply*
was "Yes, I have reproduced the problem" or "This is a known problem".
No need for any of the rest of the guff.
In any case, I remain boggled by your willingness to engage in ad
hominem attacks, even as you take offense at the anything that you find
remotely disagreeable. Before you worry about the speck in my eye, you
might want to get that log in yours checked out.

Pete

Cute.
You are "boggled" how people react to a prima donna?
Others manage to provide useful information without accompanying
with diatribe and invective.

You should try it sometime.

Oz
 
P

Peter Duniho

ozbear said:
[...]
Others manage to provide useful information without accompanying
with diatribe and invective.

Honestly, if you think anything I write is "diatribe and invective", you
need to stop using the Internet. Your skin is way too thin.

That said, I believe I've figured out the source of your apparent
hypocrisy. You are so unable to keep a civil tongue yourself, that you
simply jump to the conclusion that everyone else is acting the same way
you do, even when there's absolutely no evidence to suggest they are.

Good luck with that.

Pete
 

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