Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • George 58 posts 165 karma points
    Aug 13, 2020 @ 10:45
    George
    0

    Using razor instead of xslt error (Umbraco 7.10.3)

    We are using Umbraco 7.10.3 The majority of the macros on our website are written in XSLT and we want to start using Razor scripts instead of XSLT for better organization and compatibility with future Umbraco versions.

    I tried switching one of our existing xslt macros to use a new .cshtml file under /macroScripts/testMacro.cshtml. At first, I tried some complicated functionality, but later reduced it to a simple one liner just to make it work:

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{ var hello = "hello"; }
    

    The macro fails with the following error from the log file:

    2020-08-13 12:40:59,754 [P13364/D2/T5] WARN  umbraco.macro - Error loading MacroEngine script (file: testMacro.cshtml, Type: ''. Exception: System.Web.HttpCompileException (0x80004005): c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\d1305830\6e9ff11\App_Web_testmacro.cshtml.70df5e80.r11xm0bs.0.cs(24): error CS0234: Typen eller navneområdenavnet 'Helpers' findes ikke i navneområdet 'Microsoft.Web' (mangler der en reference til en assembly?)
    ved System.Web.Compilation.AssemblyBuilder.Compile()
    ved System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
    ved System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
    ved System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
    ved System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
    ved System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
    ved System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp)
    ved System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType[T](String virtualPath)
    ved System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType[T](String virtualPath)
    ved System.Web.WebPages.WebPageBase.CreateInstanceFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory)
    ved umbraco.MacroEngines.RazorMacroEngine.CompileAndInstantiate(String virtualPath)
    ved umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
    ved umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
    ved umbraco.macro.loadMacroScript(MacroModel macro)
    ved umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
    

    I tried adding the Microsoft.Web.Helpers dll file to the bin folder or installing it via nuget, but that produced other problems. If I remember correctly, that dll was removed in an earlier version of Umbraco, so why does a simple macro script require this library in order to run?

    Are we doing something wrong? Any suggestions how to solve this problem and run razor macros instead of xslt?

  • Marc Goodson 1775 posts 11833 karma points MVP 7x c-trib
    Aug 13, 2020 @ 17:40
    Marc Goodson
    100

    Hi George

    I think for a Macro Partial View nowadays you would have:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    at the top of your Partial View.

    What you have relates to the older 'dynamic node' razor which has been superceded by using partial view macros...

    Try Create a brand new Partial View Macro and choosing one of the starter 'snippets' to give you an idea of the style of working with these kinds of macros.

    regards

    Marc

  • George 58 posts 165 karma points
    Aug 14, 2020 @ 06:25
    George
    0

    That solved the problem!

    Another note, I realized that the partial view macro files created by Umbraco are located under this folder:

    /Views/PartialViews/macroFile.cshtml
    

    Instead of just /macroScripts When I created the macro in the correct location and using a snippet in Umbraco backoffice, everything worked!

    Thank you Marc!

Please Sign in or register to post replies

Write your reply to:

Draft