Can't run Extension Method in Layout.cshtml

Topics: Troubleshooting, Writing themes
Mar 17, 2011 at 8:41 PM

@using System;
@using System.Web.Mvc;
@using Orchard.Mvc.Html;
@using Orchard.UI.Resources;
@using Orchard.Utility.Extensions;
@using Orchard.Mvc.Extensions;

@{  
    var siteImage = Url.MakeAbsolute("~/Themes/MyTheme/Content/Images/MyImage.png");
}

This fails with a compilation error: Compiler Error Message: CS1061: 'System.Web.Mvc.UrlHelper' does not contain a definition for 'MakeAbsolute' and no extension method 'MakeAbsolute' accepting a first argument of type 'System.Web.Mvc.UrlHelper' could be found (are you missing a using directive or an assembly reference?)

If I comment that line out and attach a debugger, I can run the exact same line of code in the Immediate window. 

Confused.

Coordinator
Mar 19, 2011 at 1:23 AM

I'm guessing what you are missing is a reference to the assembly from your theme project (if you have one). Can you please check that? This might be a bug.

Mar 19, 2011 at 5:52 PM

If it is a missing reference, I can't figure it out. Theme project has refs to Orchard.Core, Orchard.Framework, and everything from lib\aspnetmvc\*. Maybe I'm missing a dependency of a dependency that I can't untangle?

Coordinator
Mar 19, 2011 at 11:26 PM

That extension is in Orchard.Framework so that's probably not the problem. Now that I think of it, this is in Razor views, so the project probably has nothing to do with it. More likely this needs to be set in the local web.config of your views folder.

Coordinator
Mar 20, 2011 at 6:48 AM

Url.Content("~/Themes/...") does what you want.

Mar 20, 2011 at 4:39 PM

Nope, it doesn't. Url.Content() returns a relative URL (/OrchardLocal/Themes/...). I'm inserting a meta tag for the Facebook Like image, the image that gets inserted on their wall (og:image, https://developers.facebook.com/docs/reference/plugins/like/). I learned through trial and error that it requires an absolute URL (http://...). 

Apr 8, 2011 at 3:56 PM

I had this once (compiling from command line) with a project where I had disabled "copy local" for the Orchard.Framework reference -- but it only failed because I additionally had enabled MvcBuildViews inside the project.

Oct 24, 2011 at 1:36 AM

I am getting this same exception when I was setting up email module.  Once I installed Email and Messaging I got a warning to install Email.Rules which when I did that it then complained that I needed the Token Module. So after I install the Token module I get this same exception...

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'System.Web.Mvc.UrlHelper' does not contain a definition for 'MakeAbsolute' and no extension method 'MakeAbsolute' accepting a first argument of type 'System.Web.Mvc.UrlHelper' could be found (are you missing a using directive or an assembly reference?)

Source Error:

 
Line 83: 
Line 84:             context.For<string>("Url")
Line 85:                 .Token("Absolute", url => new UrlHelper(_workContextAccessor.GetContext().HttpContext.Request.RequestContext).MakeAbsolute(url));
Line 86: 
Line 87:             context.For<TextField>("TextField")


Source File: e:\web\softland\Modules\Orchard.Tokens\Providers\ContentTokens.cs Line: 85


Show Detailed Compiler Output:

C:\Windows\SysWOW64\inetsrv> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\281633f8\000c6243_edf7cb01\ClaySharp.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\4a87dab6\000c6243_edf7cb01\Microsoft.Web.Infrastructure.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Linq.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\d594cbe8\000c6243_edf7cb01\Antlr3.Runtime.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\8362c4c1\000c6243_edf7cb01\NHibernate.Linq.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\af499211\000c6243_edf7cb01\System.Web.Helpers.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\01c4e5bf\000c6243_edf7cb01\System.Web.WebPages.Razor.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\e52aea17\0047ba4b_edf7cb01\Orchard.WarmupStarter.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\0c7d7030\000c6243_edf7cb01\Castle.DynamicProxy2.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_global.asax.7uq2o-hb.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\ba9901b2\000c6243_edf7cb01\Autofac.Integration.Web.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\b4463e68\00399344_edf7cb01\System.Data.SqlServerCe.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\0ed5da08\000c6243_edf7cb01\System.Web.Razor.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\0e659df6\000c6243_edf7cb01\System.Web.WebPages.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\b75ce218\000c6243_edf7cb01\System.Web.WebPages.Deployment.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\de2da784\0047ba4b_edf7cb01\Orchard.Core.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\4a2b1e3d\000c6243_edf7cb01\FluentNHibernate.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\7022098f\000c6243_edf7cb01\NHibernate.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\afe7e2b0\000c6243_edf7cb01\WebMatrix.Data.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\48e93a26\000c6243_edf7cb01\log4net.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\5d5f4afa\000c6243_edf7cb01\Autofac.Integration.Web.Mvc.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Routing\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Routing.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\b260334b\000c6243_edf7cb01\NHibernate.ByteCode.Castle.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\50826912\000c6243_edf7cb01\Autofac.Configuration.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\7a259dfe\000c6243_edf7cb01\System.Web.Mvc.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\f832b021\000c6243_edf7cb01\Castle.Core.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\c30b4626\000c6243_edf7cb01\Autofac.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Abstractions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Abstractions.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\ad41db96\001a894a_edf7cb01\Orchard.Framework.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\a9a7f148\000c6243_edf7cb01\Iesi.Collections.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\assembly\dl3\7564e48f\0074eb4c_edf7cb01\Orchard.Web.dll" /out:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.dll" /debug- /optimize+ /w:4 /nowarn:1659;1699;1701 /warnaserror-  "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.6.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.9.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.5.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.8.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.4.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.10.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.13.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.12.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.14.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.3.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.15.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.2.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.11.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.1.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.0.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eaacf491\49e58880\App_Web_orchard.tokens.csproj.f127db92.fgsf_lzw.7.cs"


Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.

e:\web\softland\Modules\Orchard.Tokens\Providers\ContentTokens.cs(85,127): error CS1061: 'System.Web.Mvc.UrlHelper' does not contain a definition for 'MakeAbsolute' and no extension method 'MakeAbsolute' accepting a first argument of type 'System.Web.Mvc.UrlHelper' could be found (are you missing a using directive or an assembly reference?)


Oct 30, 2011 at 8:57 PM

Maybe this is a solution for you:

var siteImage = new Uri(HttpContext.Current.Request.Url, Url.Content("~/Themes/MyTheme/Content/Images/MyImage.png")).ToString();