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

Add support for "first-class span types" C# language feature #3651

Open
zgabi opened this issue Feb 13, 2025 · 1 comment
Open

Add support for "first-class span types" C# language feature #3651

zgabi opened this issue Feb 13, 2025 · 1 comment

Comments

@zgabi
Copy link

zgabi commented Feb 13, 2025

Since the latest Visual Studio version (17.13)/C# version some of our code started to fail at runtime.
The problem is that Microsoft implemeted the "First-class Span types" language feature (https://github.com/dotnet/csharplang/blob/main/proposals/first-class-span-types.md)
I'm using the LangVersion=preview settings (because of the "field" keyword)

For example we have the following code:

        var ids = new Guid[] { guid1, guid2... };
        foreach (var r in session.Query<MyClass>().Where(x => ids.Contains(x.Id)))
        {
            ...
        }
 

Earlier (before 11.02.2025) this code worked, but now it throws the following exception:

NHibernate.HibernateException
  HResult=0x80131500
  Message=Evaluation failure on op_Implicit(value(System.Guid[]))
  Source=NHibernate
  StackTrace:
   at NHibernate.Linq.Visitors.NhPartialEvaluatingExpressionVisitor.Visit(Expression expression)
....
Inner Exception 1:
NotSupportedException: Specified method is not supported.
 

Because earlier the predicate expression in the Where method was calling the Enumerable.Contains extension method, but now it calls the MemoryExtensions.Contains method.

There is a workaround:

        var ids = new Guid[] { guid1, guid2... };
        foreach (var r in session.Query<MyClass>().Where(x => ((IEnumerable<Guid>)ids).Contains(x.Id)))
        {
            ...
        }

but it needs to change our code everywhere. And hard to find every places since there is no build error, only a runtime exception.

@fredericDelaporte
Copy link
Member

Another workaround, which would apply globally, would be to add custom generators for these MemoryExtensions methods, that would mimic the work of the standard generators.

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

No branches or pull requests

2 participants