The type arguments for method cannot be inferred from the usage

August 19th, 2013

Visual Studio can have problems understanding LINQ expressions in Razor views, complaining with the recurring error message when hovering the inline expression:
“The type arguments for method … cannot be inferred from the usage. Try specifying the type arguments explicitly.”

Even though the code is correct and everything works as expected, the MVC view gets cludded with warnings and Intellisense doesn’t work inside the LINQ expressions.

Solution:
Add targetFramework="4.0" in the compilation node in web.config, and then re-compile:

1
<compilation defaultLanguage="c#" targetFramework="4.0">

Leave a Reply