ket
ket

Reputation: 758

StackOverflowException on build in VS2017/2019

I have a test project that built successfully in VS2015, but the build fails due to a StackOverflowException when I attempt to build it in VS2017/2019. The final statement printed in the diagnostic log at the point before the exception occurs is this:

Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn

I've attempted to toggle the UseSharedCompilation flag between true and false, but it seems to have no effect. The issue seems to have to do with the number of chained Fluent Migrator methods (more on this below), but I don't have a way to change the code to mitigate this issue.

I'm not well versed in compilers, so I'm at a loss about what changed between VS2015 and newer versions such that this issue would suddenly crop up. Could someone help me understand, and even better, give me some build-for-dummies suggestions to get my build to work under VS2017/2019?

Details: I inherited some software that is tightly coupled to a generic dB schema shared with a bunch of similar applications. New tables and reference data is inserted into the db schema using a tool that consumes a bunch of XML files that contain both data and metadata. For the application I inherited, there was no test coverage and some 40k lines of XML content that had to be updated via search-and-replace and manual checking. To solve these and related issues, I wrote some code to parse the XML files and auto-generate C# classes with Fluent Migrator content. Some of the (non-normalized) tables have hundreds of columns, and that seems to be the specific issue that is causing the StackOverflowException. The compiler seems to be able to handle about 200 .WithColumn calls, but beyond that it bombs out. Brief except below. I mention this just to provide context about the problem and to explain why on earth I'm doing what I'm doing.

.WithColumn(nameof(ColumnDescriptions.XXX)).AsString(100).NotPublishedOffline().WithColumnDescription(ColumnDescriptions.XXX)
         //.WithColumn(nameof(ColumnDescriptions.YYY)).AsString(100).NotPublishedOffline().WithColumnDescription(ColumnDescriptions.YYY)

Upvotes: 4

Views: 759

Answers (1)

JoshVarty
JoshVarty

Reputation: 9426

I believe it's a known Roslyn bug when chaining many fluent calls together: https://github.com/dotnet/roslyn/issues/9795

From another answer the workaround seems to be to split up your fluent calls into multiple statements:

For example:

var result = x.WithColumn(nameof(ColumnDescriptions.XXX)).AsString(100).NotPublishedOffline().WithColumnDescription(ColumnDescriptions.XXX)

Can be broken up into

var temp = .WithColumn(nameof(ColumnDescriptions.XXX)).AsString(100)
var result = temp.NotPublishedOffline().WithColumnDescription(ColumnDescriptions.XXX)

Upvotes: 2

Related Questions