4

We have updated our base solution which just contains a few example renderings from Sitecore 8.1 to 8.2. Note: we are still using VS 2013, but I don't think this should be any problem?

I have updated the references and I think I've tried just about everything in terms of removing and re-adding references, deleting readding and updating Nuget packages.

In my Views whenever I use Glass Mapper editable e.g.

@Editable(Model.DataItemModel, x=>x.HeaderText)

I'm getting x=>x.HeaderText underlined with this error:

Error   4   Cannot convert lambda expression to type
'System.Linq.Expressions.Expression<System.Func<Project.Entities.HeaderSettings,object>>'
because it is not a delegate
type    c:\Projects\SitecoreMVC\Code\SitecoreMVC\Project.Web\Views\Shared\_Header.cshtml

I can't figure out what has changed. Can anyone help?

  • Did you also upgrade Glass.Mapper to the newest version? – Tamás Tárnok Dec 15 '16 at 13:14
  • Yep version 4.2.1.190 – DaveBeta Dec 15 '16 at 13:16
  • Could you compare the contents of your /Views/Web.config and /Areas/*/Views/Web.config to the default /Views/Web.config that comes with Sitecore 8.2? They should be (in most cases) identical. – Dmytro Shevchenko Dec 15 '16 at 15:17
  • Yeah it is identical because I used the one that comes with 8.2 This is still driving me bonkers – DaveBeta Dec 15 '16 at 18:15
  • @DaveBeta Is this a problem only in Visual Studio? Do the pages actually work correctly? Have you tried restarting Visual Studio? ;-) – Dmytro Shevchenko Dec 15 '16 at 19:27
4

This error (as well as many other errors) happens because of a mismatch between the used and the targeted versions of ASP.NET MVC binaries.

Sitecore 8.2 uses version 5.2.3.0 of the following assemblies:

  • System.Web.Mvc
  • System.Web.Http
  • System.Web.Http.WebHost
  • System.Net.Http.Formatting
  • System.Web.Http.Cors

You need to make sure that you have the version 5.2.3.0 of these assemblies:

  • for corresponding DLLs residing in your bin folder
  • in Web.config under configuration > system.web > compilation > assemblies
  • in the redirects in Web.config under configuration > runtime > assemblyBinding, for example:

    <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" xmlns="urn:schemas-microsoft-com:asm.v1" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" xmlns="urn:schemas-microsoft-com:asm.v1" />
    </dependentAssembly>
    
  • in installed NuGet packages

  • in references of all of your Sitecore projects
  • in Web.config files (if you have any) under /Views and /Areas/*/Views, for example:

    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    
    ...
    
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
    

You also need to ensure that the target framework in all of your projects, as well as in Web.config, is set to 4.5.2.

The error should be fixed after you perform the steps above.

  • I'm still double checking, but I don't think this is the problem. The issue appears to be related to Linq. I noticed Linq expressions such as Any aren't working in Views! @if (Model.DataItemModel.CommentFolder.Comments.Any()) Error 6 'System.Collections.Generic.IEnumerable<Project.Entities.Comment>' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Project.Entities.Comment>' could be found (are you missing a using directive or an assembly reference?) – DaveBeta Dec 15 '16 at 15:08
  • @DaveBeta OK, that sounds like a completely separate problem. Make sure that you either have @using System.Linq in your view, of <add namespace="System.Linq" /> in your /Views/Web.config under system.web.webPages.razor > pages > namespace. – Dmytro Shevchenko Dec 15 '16 at 15:13
  • If I add @using System.Linq it underlines Linq does not exist – DaveBeta Dec 15 '16 at 15:32
  • Linq works fine in a controller though – DaveBeta Dec 15 '16 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.