LINQ3 driver broken in .NET using LangVersion 14

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • 🔵 Done
    • Dotnet Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      With Langversion 14, if you use a LINQ query with a Contains Method from an array it incorrectly compiles with ReadOnlySpan causes an error

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      3.5

      How to Reproduce

      The screenshot below demonstrate that, using the langversion 14 (.NET 10) if you create a query with an array and Contains it uses the ReadOnlySpan extensino method, making the LINQ driver to fail the translation with the error System.NotSupportedException: Specified method is not supported. (just run the attached example)  **  

       

      The proof that the ReadOnlySpan is the culprit is: take the project file, set the lang versino to 13

      <LangVersion>13</LangVersion>

      Then the compiler uses the IEnumerable extension and the translation is correct. This happens even in .NET 9 project if you have Langversion 14. The worst thing is, if you have

      <LangVersion>latest</LangVersion>

       

      the code runs fine if compiled from VS2022 and has the error using the preview of VS2026.

      Additional Background

      If you use a List<String> instead of a string array everything is ok, if in the C# project file you use <langversion>13</langversion> the expression run correct.,y

        1. MongoDbDemo.zip
          2 kB
        2. image-2025-10-14-10-04-13-257.png
          image-2025-10-14-10-04-13-257.png
          50 kB
        3. image-2025-10-14-10-00-37-178.png
          image-2025-10-14-10-00-37-178.png
          52 kB

            Assignee:
            Unassigned
            Reporter:
            Gian Maria Ricci
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: