Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

ArgumentOutOfRangeException when using lambdas and line breaks #671

@senritsu

Description

@senritsu

We came across a really baffling error today when using constructors/functions that take a parameter array of lambdas. With certain combinations of line breaks, Razor throws System.ArgumentOutOfRangeException: 'count' must be non-negative.. For a complete stack trace, refer to this gist

After figuring out that it apparently is caused by line breaks in the C# code inside the razor view, we did a few tests to figure out the specifics.

short version

instanceWithMethod.Foo
        (
        x => x.Foo,
        x => x.Bar,
        x => x.Baz
        );

inside a code block in a razor view does throw System.ArgumentOutOfRangeException, but

instanceWithMethod.Foo
        (x => x.Foo, x => x.Bar, x => x.Baz);

works

long version

The code only seems to work when the parameters are all in one line, and the opening parenthesis is on the same line. The closing parenthesis does not seem to matter.

In production code we have a reproducible case where it also works if the parameters are not in one line, but the opening parenthesis still has to be on the same line as the first parameter. We could not manage to repeat this behavior in our synthetic test.

The tests were done with a new MVC web project from the template, using AspNet5 rc1.

The detailed test setup needed to reproduce this issue (beyond the code contained in the standard project template), and all mentioned cases (minus the separate views for each test that were combined into one view for brevity and can be supplied if needed) as well as the complete stack trace can be found in this gist

The same bug was apparently also reported here (forums.asp.net) without a solution (or any details, really).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions