7

I've installed Glass.Mapper.Sc (v4.3.4.196) with out any problems but in a razor view i can't use helper @Html.Glass() because i have an error that says that HtmlHelper does not contain a definition for Glass and no extension method Glass... i'm missing something?

  • Do you have the Glass.Mapper references in your project? Before you install Glass.Mapper you need to reference the Sitecore.Kernel to make it work. – Tamás Tárnok Feb 2 '17 at 14:05
  • Yes, i have Sitecore.Kernel, Glass.Mapper,Glass.Mapper.Sc and Glass.Mapper.Sc.Mvc references – Phoenix_uy Feb 2 '17 at 14:06
  • Do you have the @using Glass.Mapper.Sc.Web.Mvc at the begining of your View? – Tamás Tárnok Feb 2 '17 at 14:09
  • Adding that, i have the error The type 'Expression<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' (i have that reference) – Phoenix_uy Feb 2 '17 at 14:10
  • 2
    Let us continue this discussion in chat. – Tamás Tárnok Feb 2 '17 at 14:24
10

The problem was with MVC setup in the project not with Glass. This was the solution - http://samirvaidya.blogspot.hu/2015/10/the-type-expression-is-defined-in.html.

The error was exactly

The type 'Expression<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

And non of the HtmlExtensions was not working. Solution is that you need the following references in your web.config.

<compilation debug="true" targetFramework="4.5">
    <assemblies>
        <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />   
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
</compilation>
5

I added

@using Glass.Mapper.Sc.Web.Mvc 

on Top and it solved my problem

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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