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

Contains extension method on arrays is resolved from MemoryExtensions instead of Linq breaking EF queries #109869

Closed
ilGianfri opened this issue Nov 15, 2024 · 2 comments
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Comments

@ilGianfri
Copy link

Description

When using the .Contains extension method on an array inside an EF query, it uses the method .Contains from System MemoryExtensions instead of the System.Linq one breaking the query.
It throws "An exception was thrown while attempting to evaluate the LINQ query parameter expression"

Disabling LangVersion preview "fixes" the issue.

Reproduction Steps

  • Create a console project with EF In Memory database
  • Set langversion preview
  • Add data to the db table
  • Create a string[] with some values in it
  • Write a query that searches inside the db table the values in the string[] with a contains
  • Run the app

I've attached a simple repro app ConsoleApp2.zip

Expected behavior

The .Contains method should be resolved to System.Linq or it should be accepted by EF so that the query can be translated to sql.

Actual behavior

The .Contains method is resolved from System MemoryExtensions that works on Spans making it not supported as a query

Regression?

I think this is a regression because if I use LangVersion Latest it starts working

Known Workarounds

Use a List instead of an array or simply use LangVersion Latest instead of Preview.

Configuration

  • Which version of .NET is the code running on? .NET 8.0 and 9.0 both have this issue with langversion Preview
  • What OS and version, and what distro if applicable? Windows 11 26100.2314
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? I don't think its specific to this config

Other information

I think the issue is cause by the OverloadResolutionPriority set to -1 in the MemoryExtensions .Contains method

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 15, 2024
@stephentoub
Copy link
Member

Duplicate of #109757 ?

@ilGianfri
Copy link
Author

Duplicate of #109757 ?

Sorry I missed that one, I've posted a comment with the repro app on that issue now.

@stephentoub stephentoub closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Nov 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

No branches or pull requests

2 participants