C# Receiving and error "An expression is too long or complex to compile"

Vincent Faller 0 Reputation points
2023-08-22T14:39:41.9466667+00:00

After updating Visual Studio 2022 on 8/15, I started receiving CS8078 "An expression is too long or complex to compile" error. The code still compiles in Visual Studio 2019. I can't put the exact code here but I am using FizzWare.NBuilder to create a list of objects. I am chaining together several commands that I think is causing the compiler to fail.

here is an example in .NET Framework 4.6.1. It seems to fail as soon as I add the 18th .TheNext line

using FizzWare.NBuilder;
using System.Linq;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var objs = Builder<SomeObject>
              .CreateListOfSize(20)
             .TheFirst(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
             .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
              .TheNext(1).With(x => x.Property1 = "Value1").With(x => x.Property2 = "Value2").With(x => x.Property3 = "Value3").With(x => x.Property4 = "Value3").With(x => x.Property5 = "Value5").With(x => x.Property6 = "Value6").With(x => x.Property7 = "Value7").With(x => x.Property8 = "Value8").With(x => x.Property9 = "value9").With(x => x.Property10 = "value10").With(x => x.Property11 = "value11").With(x => x.Property12 = "value12").With(x => x.Property13 = "value13").With(x => x.Property14 = "value14").With(x => x.Property15 = "value15").With(x => x.Property16 = "value16").With(x => x.Property17 = "value17").With(x => x.Property18 = "value18").With(x => x.Property19 = "value19").With(x => x.Property20 = "value20").With(x => x.Property21 = "value21").With(x => x.Property22 = "value22").With(x => x.Property23 = "value23").With(x => x.Property24 = "value24").With(x => x.Property25 = "value25").With(x => x.Property26 = "value26").With(x => x.Property27 = "value27").With(x => x.Property28 = "value28").With(x => x.Property29 = "value28")
             .Build().ToList();
        }
    }

    internal class SomeObject
    {
        public string Property1 { get; set; }
        public string Property2 { get; set; }
        public string Property3 { get; set; }
        public string Property4 { get; set; }
        public string Property5 { get; set; }
        public string Property6 { get; set; }
        public string Property7 { get; set; }
        public string Property8 { get; set; }
        public string Property9 { get; set; }
        public string Property10 { get; set; }
        public string Property11 { get; set; }
        public string Property12 { get; set; }
        public string Property13 { get; set; }
        public string Property14 { get; set; }
        public string Property15 { get; set; }
        public string Property16 { get; set; }
        public string Property17 { get; set; }
        public string Property18 { get; set; }
        public string Property19 { get; set; }
        public string Property20 { get; set; }
        public string Property21 { get; set; }
        public string Property22 { get; set; }
        public string Property23 { get; set; }
        public string Property24 { get; set; }
        public string Property25 { get; set; }
        public string Property26 { get; set; }
        public string Property27 { get; set; }
        public string Property28 { get; set; }
        public string Property29 { get; set; }
    }
}


Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,449 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 34,311 Reputation points Microsoft External Staff
    2023-08-23T08:10:03.7666667+00:00

    Hello @Vincent Faller ,

    Welcome to Microsoft Q&A forum.

    The error message is clear, currently, you may need to modify the code and make the expression not too long or complex(split it).

    I tested on my side and I can confirm that this works in VS 2019 but the error appears in VS 2022. It’s possible that this may be a potential issue. I strongly recommend submitting a ticket on our Developer Community for further investigation.

    If you can confirm that it works in previous version of VS 2022, you can try to rollback VS 2022 from VS Installer, this is another workaround temporarily.

    If you do submit a ticket, please kindly share the ticket link here for better tracking.

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.