Skip to content

ExpressionBinderBase issue with .NET 6 #2518

Closed
@ysmoradi

Description

@ysmoradi

This exception should occur in ASP.NET Core OData 8 too, because I'm talking about the code which exists in Shared section of repository codes

I've updated my owin / web api 2 project to .NET 6 and I'm getting a Sequence contains more than one matching element at following:

internal static readonly MethodInfo EnumTryParseMethod = typeof(Enum).GetMethods()
                        .Single(m => m.Name == "TryParse" && m.GetParameters().Length == 2);

https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData.Shared/Query/Expressions/ExpressionBinderBase.cs#L44-L45

Assemblies affected

OData WebApi lib 7.5.8

Reproduce steps

Run following in .NET 6 console app:

typeof(Enum).GetMethods()
                        .Single(m => m.Name == "TryParse" && m.GetParameters().Length == 2)

Expected result

TryParse method should get reflected.

Actual result

Invalid operation exception

Additional detail

In .NET 5 and older versions, we only have TryParse method which accepts a string value.
In .NET 6, a new overload has been added which accepts ReadOnlySpan<char>

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions