Compiler Error CS1941
The type of one of the expressions in the 'clause' clause is incorrect. Type inference failed in the call to 'method'.
Type inference in query expressions flows from the type of the elements in the data source(s).
To correct this error
- If it is not immediately obvious why the error is occurring, examine the query carefully and trace the type of the result of each clause from the data source to the point where the error is occurring.
Example
The following code generates CS1941 because the equals
operator is being asked to compare an int
to a string
.
// cs1941.cs
using System.Collections;
using System.Linq;
class Test
{
static int Main()
{
var nums = new[] { 1, 2, 3, 4, 5, 6 };
var words = new string[] { "lake", "mountain", "sky" };
IEnumerable e = from n in nums
join w in words on n equals w // CS1941
select w;
return 0;
}
}
The method in which type inference fails is the method that the query clause is translated to at compile time.
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for