You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
When trying to iterate over a collection of named Tuples, I receive a runtime error that the tuple does not contain the named member.
public class MyClass
{
public static IEnumerable<(string name, int age)> GetPeople()
{
return new(string, int)[] {
("Dave", 32),
("Mary", 29),
};
}
}
Razor
<div>
@foreach (var person in MyClass.GetPeople())
{
<p>@person.name</p>
}
</div>
At runtime, the view will throw the following exception
An unhandled exception has occurred while executing the request
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
/Views/Default/Test.cshtml(84,34): error CS1061: 'ValueTuple<string, int>' does not contain a definition for 'name' and no extension method 'name' accepting a first argument of type 'ValueTuple<string, int>' could be found (are you missing a using directive or an assembly reference?)
If I change my class to return unnamed Tuples, and change the Razor code use Item1, and Item2 instead, it works perfectly.
I am able to iterate over the collection in my controller, but it will not work in a Razor view.
The text was updated successfully, but these errors were encountered:
Ya, sorry about that @MaxxDelusional. Tooling runs with a different Roslyn than we use at runtime 😄. Follow #1046 for updates on when C#7 will make its way to you.
When trying to iterate over a collection of named Tuples, I receive a runtime error that the tuple does not contain the named member.
Razor
At runtime, the view will throw the following exception
If I change my class to return unnamed Tuples, and change the Razor code use Item1, and Item2 instead, it works perfectly.
I am able to iterate over the collection in my controller, but it will not work in a Razor view.
The text was updated successfully, but these errors were encountered: