5
votes

I'm trying to create the simplest possible RazorEngine startup project with full IntelliSense in Visual Studio 2015.

I'm strugguling on making Linq extensions available in the templates. They are correctly compile, but Visual Studio still ouput an error when the template is open:

'List < string > ' does not contain a definition for 'Select' accepting a first argument of type 'List < string > ' could be found (are you missing a using directive or an assembly reference?)

And the error on @using System.Linq, but the error is:

The type or namespace 'Linq' does not exist in the namespace 'System'

What am I missing?

The full code is on this branch : https://github.com/cyrilgandon/RazorEngineGenerator/tree/LinqUnavailable

I can see that some posts advise to add references in the app.config, but I don't see anywhere in the docs (link) the need to do that.

4
Perhaps you suffer from the same problem as the problem for the answer here: stackoverflow.com/a/23983883/858757Silvermind
Tried that, do not work. IntelliSense is working, it is the support for Linq which is not.Cyril Gandon
Closing the cshtml file made the error disappear... odd.Thomas

4 Answers

1
votes

I had same issue, and I have tried everything I could find here and nothing worked. So finally I have changed .NET framework version from 4.0 to 4.5.2 and problem was gone.

0
votes

I fixed the same issue by adding reference to System.Web.WebPages and System.Web.WebPages.Razor in project with custom templates. I don't have any web.config in this project.

0
votes

I had same issue, the problem was in web.config (not the one under Views) which had these lines

<dependentAssembly>
    <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>

After removing those lines the problem was gone and intellisense started working again for Linq expressions.

Update:

Alright, after uninstalling VS 2013 the errors came back. But it got fixed after installing these two MVC4 - https://www.microsoft.com/en-us/download/details.aspx?id=30683 Web pages 2.0 - https://www.microsoft.com/en-us/download/details.aspx?id=34600

I think it was fixed after installing Web pages 2.0 but I installed MVC4 as well to be in safer side.

-1
votes

Extension methods only work as extension methods when they are in a referenced namespace. Try adding:

@using System.Linq