By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,222 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,222 IT Pros & Developers. It's quick & easy.

Large string constant causes C# compiler crash

P: n/a
I created a C# application with some large string constants and whenever I
try to build the solution the compiler crashes with no error message. On
further analysis the problem seems to occur when the string constant has
around 2100 character. I tried changing the constant declaration to a string
variable declaration and it works fine.

Any ideas?

The following code can be used to reproduce the error:

const string TEST =
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0" +
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0";

Regards
Gnik
Nov 16 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
As far as I am concerned, that shouldn't cause a crash -and indeed doesn't
on my machine. Maybe you should post the full code of your problem (perhaps
you have a physical memory problem on your machine?).
"Gnik" <Gn**@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
I created a C# application with some large string constants and whenever I
try to build the solution the compiler crashes with no error message. On
further analysis the problem seems to occur when the string constant has
around 2100 character. I tried changing the constant declaration to a
string
variable declaration and it works fine.

Any ideas?

The following code can be used to reproduce the error:

const string TEST =
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0";

Regards
Gnik

Nov 16 '05 #2

P: n/a
Gnik wrote:
I created a C# application with some large string constants and whenever I
try to build the solution the compiler crashes with no error message. On
further analysis the problem seems to occur when the string constant has
around 2100 character. I tried changing the constant declaration to a string
variable declaration and it works fine.

Any ideas?


Not able to reproduce here. Compiles and executes fine.
--
Tom Porterfield
Nov 16 '05 #3

P: n/a
The full code is simply that line of code pasted into the Main function of a
default console application. It was a simple test app to diagnose the issue.

I've tried the same thing on 2 different machines with the same results both
running Windows XP SP2, one with 256 Mb RAM and the other with 1 Gb RAM. I'm
on Visual Studio .NET 2003 (7.1.3088) and .NET Framework 1.1 SP1 (1.1.4322)

"Mark Broadbent" wrote:
As far as I am concerned, that shouldn't cause a crash -and indeed doesn't
on my machine. Maybe you should post the full code of your problem (perhaps
you have a physical memory problem on your machine?).
"Gnik" <Gn**@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
I created a C# application with some large string constants and whenever I
try to build the solution the compiler crashes with no error message. On
further analysis the problem seems to occur when the string constant has
around 2100 character. I tried changing the constant declaration to a
string
variable declaration and it works fine.

Any ideas?

The following code can be used to reproduce the error:

const string TEST =
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0";

Regards
Gnik


Nov 16 '05 #4

P: n/a
The full code is simply that line of code pasted into the Main function of a
default console application. It was a simple test app to diagnose the issue.

I've tried the same thing on 2 different machines with the same results both
running Windows XP SP2, one with 256 Mb RAM and the other with 1 Gb RAM. I'm
on Visual Studio .NET 2003 (7.1.3088) and .NET Framework 1.1 SP1 (1.1.4322)

"Mark Broadbent" wrote:
As far as I am concerned, that shouldn't cause a crash -and indeed doesn't
on my machine. Maybe you should post the full code of your problem (perhaps
you have a physical memory problem on your machine?).


Nov 16 '05 #5

P: n/a
Not reproducable so there must be a difference, any non visible characters
embedded perhaps? Use a binary view to see that.

"Gnik" <Gn**@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
The full code is simply that line of code pasted into the Main function of
a
default console application. It was a simple test app to diagnose the
issue.

I've tried the same thing on 2 different machines with the same results
both
running Windows XP SP2, one with 256 Mb RAM and the other with 1 Gb RAM.
I'm
on Visual Studio .NET 2003 (7.1.3088) and .NET Framework 1.1 SP1
(1.1.4322)

"Mark Broadbent" wrote:
As far as I am concerned, that shouldn't cause a crash -and indeed
doesn't
on my machine. Maybe you should post the full code of your problem
(perhaps
you have a physical memory problem on your machine?).
"Gnik" <Gn**@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
>I created a C# application with some large string constants and whenever
>I
> try to build the solution the compiler crashes with no error message.
> On
> further analysis the problem seems to occur when the string constant
> has
> around 2100 character. I tried changing the constant declaration to a
> string
> variable declaration and it works fine.
>
> Any ideas?
>
> The following code can be used to reproduce the error:
>
> const string TEST =
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
> +
> "1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0";
>
> Regards
> Gnik


Nov 16 '05 #6

P: n/a
"Tom Porterfield" <tp******@mvps.org> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
Not able to reproduce here. Compiles and executes fine.


Also, compiles & executes using Jeff Kay's "Snippet Compiler"

--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

Nov 16 '05 #7

P: n/a
Gnik wrote:
The full code is simply that line of code pasted into the Main function of a
default console application. It was a simple test app to diagnose the issue.

I've tried the same thing on 2 different machines with the same results both
running Windows XP SP2, one with 256 Mb RAM and the other with 1 Gb RAM. I'm
on Visual Studio .NET 2003 (7.1.3088) and .NET Framework 1.1 SP1 (1.1.4322)


OK, I had pasted the code outside of main, at the class level. Putting
it inside main produces the same result as you are reporting.
--
Tom Porterfield
Nov 16 '05 #8

P: n/a
Having spent a bit of time with this there are several clear things.
1. Compiles ok when const is a class member.
2. Falls over when large string const is within Class member (have tried
methods and properties -static or not does not make a difference)
3. Length of const IS making a difference as to whether falls over or not.
4. Your statement IS VALID.

This seems to be a bug in visual studio since your project will compile with
the command line util csc.

Your solution is thus.. declare the constants as private class level members
rather than within the method calls. This is actually good practice too
since you would otherwise be re-initializing a brand new const upon every
method call wheras declaring them as class members they will be initialized
once only.

See end for code...

Br,

Mark.

P.S. Good problem find!
//CODE
using System;

namespace LargeStringConstWorkaround
{
/// <summary>
/// Class demonstrates a VS problem with declaring of large string consts
within Class member methods and properties
/// </summary>
class MyClass
{
//This size constant here is OK
const string test =
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0";

[STAThread]
static void Main(string[] args)
{
/*This size constant here will cause VS to crash
const string test =
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0";
*/
Console.WriteLine(test);
}
}
}

"Gnik" <Gn**@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
I created a C# application with some large string constants and whenever I
try to build the solution the compiler crashes with no error message. On
further analysis the problem seems to occur when the string constant has
around 2100 character. I tried changing the constant declaration to a
string
variable declaration and it works fine.

Any ideas?

The following code can be used to reproduce the error:

const string TEST =
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0"
+
"1234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0";

Regards
Gnik

Nov 16 '05 #9

P: n/a

"Mark Broadbent" <no****@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Having spent a bit of time with this there are several clear things.
1. Compiles ok when const is a class member.
2. Falls over when large string const is within Class member (have tried
methods and properties -static or not does not make a difference)
3. Length of const IS making a difference as to whether falls over or not.
4. Your statement IS VALID.

This seems to be a bug in visual studio since your project will compile
with the command line util csc.


On the plus side, it appears that its fixed in whidbey, atleast for up to
three times the length of the repo case.
Nov 16 '05 #10

P: n/a
Excellent Daniel, always good to know.

I'm guessing that using constants the way gnik wanted to is probably quite a
rare scenario anyway, because the only reason you would want to put it's
declaration inside a class member is if it is unlikely to be called
(therefore having a slight potential benefit over declaring as a private
class const).

Thanks for your input too.

Br,

Mark.

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:OP**************@TK2MSFTNGP15.phx.gbl...

"Mark Broadbent" <no****@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Having spent a bit of time with this there are several clear things.
1. Compiles ok when const is a class member.
2. Falls over when large string const is within Class member (have tried
methods and properties -static or not does not make a difference)
3. Length of const IS making a difference as to whether falls over or
not.
4. Your statement IS VALID.

This seems to be a bug in visual studio since your project will compile
with the command line util csc.


On the plus side, it appears that its fixed in whidbey, atleast for up to
three times the length of the repo case.

Nov 16 '05 #11

P: n/a
Thanks for the suggestions, it's a relief to know it's not a problem with my
setup. I'll recode to put the constants at class level as in this case it
makes no difference in this particular application.

I was actually using the constants for SQL statements, bad practice I know,
but I had some issues with passing parameters to Access stored queries. I
need to go back a revisit that, but I'll save it for another thread when I
have more time.

Thanks again.

Gnik

"Mark Broadbent" wrote:
Excellent Daniel, always good to know.

I'm guessing that using constants the way gnik wanted to is probably quite a
rare scenario anyway, because the only reason you would want to put it's
declaration inside a class member is if it is unlikely to be called
(therefore having a slight potential benefit over declaring as a private
class const).

Thanks for your input too.

Br,

Mark.


Nov 16 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.