1

I have a code like this:

SomeObject.MakeFluent()
   .AddProperty(new MyProperty() { ... })
   .AddProperty(new MyProperty() { ... })
   .AddProperty(new MyProperty() { ... })
   .AddProperty(new MyProperty() { ... })
   .AddProperty(new MyProperty() { ... })
   //[+1024 times]
   .AddProperty(new MyProperty() { ... });

On compile, I get a csc.exe error, stack overflow. If I change the chained method call to:

var fluentAux = SomeObject.MakeFluent();
fluentAux.AddProperty(new MyProperty() { ... });
fluentAux.AddProperty(new MyProperty() { ... });
fluentAux.AddProperty(new MyProperty() { ... });

The code above works fine.

Is there a way to configure max stack call on VS2015's C# compiler? I ask because on VS2013, this issue doesn't happen.

Has the VS2015 compiler become less resilient?

Note: The COMPILER is returning 'stack overflow', not my program.

Eduardo Elias Saléh
  • 806
  • 1
  • 11
  • 23
  • 2
    This seems like a big code smell. Wouldn't it be easier to use some sort of loop to add the property rather than adding 1024 chained statements to do it? `foreach(var property in properties) { fluentAux.AddProperty(property); } ` – mason Mar 15 '16 at 21:06
  • Possible duplicate of [How to change stack size for a .NET program?](http://stackoverflow.com/questions/2556938/how-to-change-stack-size-for-a-net-program) – mason Mar 15 '16 at 21:08
  • How is that `AddProperty()` method implemented? Fluent or not, nothing appears to be called recursively on the surface. Perhaps `AddProperty()` is doing a lot more than it should in ways it shouldn't. – Jeff Mercado Mar 15 '16 at 21:21
  • 2
    Sounds like a compiler bug, I'd raise an issue on GitHub: https://github.com/dotnet/roslyn – DaveShaw Mar 15 '16 at 21:31
  • 1
    Yet another Roslyn issue, you'll have to click the New Issue button. Don't expect too much, there are thousands more important ones and this one is rather structural, the workaround is obvious. – Hans Passant Mar 15 '16 at 21:35
  • 1
    This code is automatically generated. I just changed the generator to break each line. But, It seems that this kind of thing shouldn't break the compiler that easy, don't you think? I'll open a bug on git hub. – Eduardo Elias Saléh Mar 16 '16 at 12:08

1 Answers1

0

Opened, as suggested by @DaveShaw, an issue on github: https://github.com/dotnet/roslyn/issues/9795

Eduardo Elias Saléh
  • 806
  • 1
  • 11
  • 23