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 LargeStringCons tWorkaround
{
/// <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 =
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890";
[STAThread]
static void Main(string[] args)
{
/*This size constant here will cause VS to crash
const string test =
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890";
*/
Console.WriteLi ne(test);
}
}
}
"Gnik" <Gn**@discussio ns.microsoft.co m> wrote in message
news:A7******** *************** ***********@mic rosoft.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 =
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890"
+
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890";
Regards
Gnik