Build error: “An expression is too long or complex to compile”

后端 未结 10 1794
无人及你
无人及你 2020-12-11 15:57

Every now and then when I build a specific solution, I\'ll get a random amount of \"An expression is too long or complex to compile\" in the Error List window. However, the

10条回答
  •  萌比男神i
    2020-12-11 16:16

    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 initialized by collection initializer.

    Something like this:

    public class Class
    {
    
        public List BigList
        {
            get
            {
                return new List()
                {
                    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"}
                }
            }
        }
    }
    

提交回复
热议问题