Conflict on Razor versions, please help

Topics: Core, Writing modules
Feb 7 at 11:01 AM
Hi,
please help me with this issue.
I'm getting this kind of warnings (that prevents my module to compile because @model and @ViewBag are not recognized anymore) that seems to be related to the Razor version.
In the first line (@model) of my cshtml view I get the following:
... ASP.NET runtime error: 
[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. 
Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. 
Type B originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. 
On my dev computer's GAC I have two versions of the System.Web.WebPages.Razor ( I don't know why as I have one only .net framework 4.0 installed).
One is v4.0_1.0.0.0, the other is v4.0_2.0.0.0.
Removing one of them from the GAC doesn't lead to any result.

Here below are the relevant sections of my web.config (from Orchard.Web) for Razor.
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <remove name="host"/>
            <remove name="pages"/>
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
        </sectionGroup>
    </configSections
    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
            <namespaces>
                <add namespace="System.Web.Mvc"/>
                <add namespace="System.Web.Mvc.Ajax"/>
                <add namespace="System.Web.Mvc.Html"/>
                <add namespace="System.Web.Routing"/>
                <add namespace="System.Web.WebPages"/>
                <add namespace="System.Linq"/>
                <add namespace="System.Collections.Generic"/>
                <add namespace="Orchard.Mvc.Html"/>
            </namespaces>
        </pages>
    </system.web.webPages.razor>
<runtime>
        <gcServer enabled="true"/>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="App_Data/Dependencies"/>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.WebPages.Deployment" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-3.3.1.4000" newVersion="3.3.1.4000"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da"/>
                <bindingRedirect oldVersion="2.2.0.0-2.6.3.862" newVersion="3.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
                <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
I don't understand if the conflict is coming from the two versions on my GAC, or from one only of them, conflicting with the Orchard one presente at /lib/aspnetvmc whose referenced from Orchard.Web.

Please help.
I'm stuck here without moving.

Thanks in advance.
Feb 7 at 3:03 PM
Edited Feb 7 at 3:04 PM
Ok.
the problem is not the GAC as if I create a brand new MVC application in visual studio, everything works fine, I have my intellisense and halpers.

On my Orchard module I'm plenty of this warnings and errors and I don't have my full intellisence: for example I have @html.Label but not @html.LabelFor<>

Why is this happening?
Could you please help me getting my intellisense back?

Thanks
Feb 10 at 8:12 PM
Edited Feb 10 at 8:12 PM
edtruant wrote:
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <remove name="host"/>
            <remove name="pages"/>
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
        </sectionGroup>
    </configSections
Try updating the web.config files to include a razor section with version 2.0.0.0.

The assembly redirect works at runtime, but the intellisense uses the web.config section version
Feb 11 at 8:50 AM
Thanks Erik,
I did already and it came to nothing.
I tried that in my Orchard.Web's web.config, then in in my module's web.config and finally I put the same web.config in folder where my view is.

Still nothing.
Feb 11 at 11:53 AM
Problem solved.
After inspecting this article http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806 and Orchard's mvc assemblies under /lib/aspnetmvc,
I've understood that Orchard uses MVC 4 to run (I think), while its solution's web.configs refer in general to mvc3.
To keep my Orchard running and making any warnings and errors disappearing from Visual Studio and getting my intellisense back, all in one, I had to do the following:

Replace System.Web.WebPages.Razor, Version=1.0.0.0, with version 2.0.0.0, as Erik suggested in the above reply.

Replace
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
with
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

Replace
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
with
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Replace
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
with
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

while, in the main web.config (Orchard.Web) I had to check that assembly redirects were pointing the right assemblies versions (it was so).
Marked as answer by edtruant on 2/11/2014 at 3:54 AM
Feb 11 at 4:45 PM
I´m also having this problem in Visual Studio 2013, i´ve tried all that you mentioned and still no intellisense, neither on orchard helpers.
But opening the same solution in Visual Studio 2012 it work´s fine.
Meanwhile i´m back on VS 2012 untill another solution is found
Feb 12 at 9:18 AM
I've checked the above steps I did in order to get my result.
I confirm that they're all that I needed to do.
I'd suggest to stop IIS, clean and rebuild the solution, and then see if intellisense is back.
Feb 12 at 1:37 PM
I´ve repeated all the steps above, now i do get razor intellisense (probably i did something wrong before), but still missing orchard helpers like @T, WorkContext and so on.
Feb 13 at 8:48 AM
nduarte wrote:
I´ve repeated all the steps above, now i do get razor intellisense (probably i did something wrong before), but still missing orchard helpers like @T, WorkContext and so on.
What version of Orchard are you using?

Big chance that 1.7 has these errors on VS2013, due to not all config files being updated.
1.x (aka 1.8) should fix all of that on VS2013
Feb 13 at 12:40 PM
I´ve tried 1.x and it has no errors related with intellisense, all the files are updated to mvc 5 and asp.net 4.5.
The version i´m using now is 1.7.2 because i´m working on a project for client that is going to production next week, and this version is stable, i stil didn´t have time to test version 1.x thoroughly.
Thank´s.