Build error: "An expression is too long or complex to compile"
FYI, that error is characteristic of the compiler running out of stack space. Typically that happens when you throw a "deep recursion" problem at the compiler, like say,
int x = (1 + (1 + (1 + (1 + ......... + 1 ) + 1 ) + 1 ) + 1);
say, several thousand deep. The syntactic and semantic analyzers are both recursive-descent analyzers and therefore prone to running out of stack space in extreme scenarios.
I have no idea why shutting down and starting over would affect that, though. That is really strange.
If you get a solid repro, I'd love to see it. Either post it here, or enter a bug on Connect and we'll have a look at it. Without a solid repro though it is very hard to say what is going on here.
I got this error in one project when I switched from Visual Studio 2012 to Visual Studio Community 2013.
In my case it was giant file (25k lines, not written by me) with had List<string[]>
initialized by collection initializer.
Something like this:
public class Class
{
public List<string[]> BigList
{
get
{
return new List<string[]>()
{
new string[]{"foo","bar"},
new string[]{"foo","bar"},
new string[]{"foo","bar"},
new string[]{"foo","bar"},
.
.
.
.
.
new string[]{"foo","bar"},
new string[]{"foo","bar"},
new string[]{"foo","bar"},
new string[]{"foo","bar"}
}
}
}
}
I changed it to string[][]
and the project started to compile
public class Class
{
public string[][] BigList
{
get
{
return new string[][]
{
new string[]{"foo","bar"},
new string[]{"foo","bar"},
new string[]{"foo","bar"},
new string[]{"foo","bar"},
.
.
.
.
.
new string[]{"foo","bar"},
new string[]{"foo","bar"},
new string[]{"foo","bar"},
new string[]{"foo","bar"}
}
}
}
}
When building you can see the the build output the last folder it checks before it fails. I removed the files in that folder and brought them back one by one. Finally found the issue. I dont know exactly what it is but it was a .aspx page with lots of HTML. It wasnt used often so I just removed it from the project and now it compiles.