Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpressionBinderBase issue with .NET 6 #2518

Closed
ysmoradi opened this issue Jul 4, 2021 · 4 comments
Closed

ExpressionBinderBase issue with .NET 6 #2518

ysmoradi opened this issue Jul 4, 2021 · 4 comments
Assignees

Comments

@ysmoradi
Copy link
Contributor

ysmoradi commented Jul 4, 2021

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>

@habbes
Copy link
Contributor

habbes commented Jul 7, 2021

Hi @ysmoradi thanks for reporting this. Would you be willing to contribute a PR to fix this? We'd be happy to review your PR and support you in the process.

@ysmoradi
Copy link
Contributor Author

ysmoradi commented Jul 7, 2021

Thanks, @habbes
I've linked PR #2520

@Treit
Copy link

Treit commented Dec 3, 2021

@habbes I am hitting this issue attempting to update some projects to .NET 6. The problem I am having is that the newest NuGet package for this project does not support .NET Standard 2.0.

We have a mixed codebase that consists of both .NET Framework and .NET Core projects and the code that is using the Microsoft.AspNetCore.OData package (and hitting this bug) is a .NET Standard 2.0 project that is shared by both .NET Framework and .NET Core projects.

Is it possible to backport this fix to a version of the NuGet package that support .NET Standard 2.0?

@Treit
Copy link

Treit commented Dec 3, 2021

I just discovered that the 7.5.12 version of the package, which is .NET Standard compatible, appears to have this fix so I am unblocked. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants