CodeConverter
CodeConverter copied to clipboard
VB -> C#: error CS8122 when using is null instead of == null
My actual VB.Net code is a complicated LINQ query that gets error CS8122 on a part that says Where (pd.Record_Type Is Nothing Or pd.Record_Type = "Acreage")
and gets converted to where (pd.Record_Type is null | pd.Record_Type == "Acreage")
but here is some code that might be easier to reproduce:
VB.Net input code
Dim x As Object = Nothing
Dim expression As System.Linq.Expression(Of Func(Of Boolean)) = Function() x Is Nothing
Erroneous output
object x = null;
System.Linq.Expressions.Expression<Func<bool>> expression = () => x is null; // CS8122
Visual Studio error:
CS8122 An expression tree may not contain an 'is' pattern-matching operator.
Expected output (replace "is" with "==")
object x = null;
System.Linq.Expressions.Expression<Func<bool>> expression = () => x == null; // fine
Details
- Product in use: e.g. VS extension
- Version in use: 9.0.2.0