Copied to clipboard

Flag this post as spam?

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


  • lucuma 261 posts 563 karma points
    Sep 07, 2012 @ 18:08
    lucuma
    0

    Razor Errors - All of a sudden

    I upgraded my webmatrix and now out of the blue I'm getting these errors on two razor scripts:

    Error loading MacroEngine script (file: , Type: ''
    c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\1cd0c4cd\ec4d3235\App_Web__footerlinks.cshtml.70df5e80.rotyyknj.0.cs(273): error CS1513: } expected
      at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)

    The strange thing is that if I remove all the contents of a script so it looks like the following, it still generates the same error.  Any help here?

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines
    
    @{ 
        var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level);
    
        var parent = @Model.AncestorOrSelf(level);
    
        if (parent != null)
        {
    
        }
    }
    
    

     

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Sep 09, 2012 @ 19:48
    Sebastiaan Janssen
    0

    Since there isn't 273 lines in this razor file I'm thinking it's some caching you're seeing. Is the razor macro cached?

    I have copied your exact code into a razor macro and it's not throwing any errors. Try adding ?umbDebugShowTrace=true to your URL and scroll down to look for the red error to see what it says.

    I'm using WebMatrix 2, the final version that was released a few days ago.

  • lucuma 261 posts 563 karma points
    Sep 10, 2012 @ 15:23
    lucuma
    0

    Sorry the error was when the full partial was being called, but the same error occurs (different line number) with just the above code which to me does't have any issues. When I uplaod it to my webserver, it runs perfectly fine (the full macro or the short code above).

    I am calling it via @RenderPage().....  This started to occur with a webmatrix upgrade from last week.. The full error:  http://screencast.com/t/US4b1Ulmzw

    This is how it is called:

                <umbraco:Macro ID="Macro3" runat="server" language="cshtml">@RenderPage("~/macroScripts/MainNavigation.cshtml")</umbraco:Macro>
  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Sep 10, 2012 @ 15:46
    Sebastiaan Janssen
    0

    Does it work when you implement it as a macro instead of using inline razor code in the template (not saying it's the best solution, just trying to pinpoint the problem area).

  • lucuma 261 posts 563 karma points
    Sep 10, 2012 @ 22:36
    lucuma
    0

    Still a no go however I did fix it.  I have no idea why it works but I made the following change (similar to both scripts that were failing, others weren't).  Again this just started all of a sudden and it compiles/run fine on the  server but not on my dev machine.   

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines

    @{
       
    var level =String.IsNullOrEmpty(Parameter.Level)?1:int.Parse(Parameter.Level);
       
       
    var parent =@Model.AncestorOrSelf(level);
    }
      
    @if(parent !=null)
     
    {
       
     
    }
  • Jason 22 posts 41 karma points
    Oct 17, 2012 @ 18:15
    Jason
    0

    I'm having the same issues after upgrading webmatrix.  No changes were made.  Errors below: 

    rror Loading Razor Script (file: ) c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fba73c04\9cd6049e\App_Web_inline-e7ec17aa061628d3bfac4b57f36964d6.cshtml.ae9e2569.isnvsjcc.0.cs(60): error CS1513: } expected    at System.Web.Compilation.AssemblyBuilder.Compile()
      at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
      at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
      at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
      at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
      at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
      at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp)
      at System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType[T](String virtualPath)
      at System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance[T](IVirtualPathFactory factory, String virtualPath)
      at System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType[T](String virtualPath)
      at System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance[T](IVirtualPathFactory factory, String virtualPath)
      at System.Web.WebPages.WebPageBase.CreateInstanceFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory)
      at umbraco.MacroEngines.RazorMacroEngine.CompileAndInstantiate(String virtualPath)
      at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
      at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)

    Error loading MacroEngine script (file: , Type: ''
    c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fba73c04\9cd6049e\App_Web_inline-09cbddcbf5c3f65e327d878d0bb90b48.cshtml.ae9e2569.fqzrrsfn.0.cs(61): error CS1513: } expected
      at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)

     


     

  • Jason 22 posts 41 karma points
    Oct 17, 2012 @ 20:08
    Jason
    0

    I was able to correct the problem by moving the inline razor to a .cshtml file and creating a macro.  Once the macro was inserted and the inline razor removed the code worked as expectd.

  • Jason 22 posts 41 karma points
    Oct 17, 2012 @ 20:19
    Jason
    0

    Also lucuma in the razor code try removing the @ before the Model.AncestorOrSelf(level) as I it is already covered by the @{ before the variable declaration.  This corrected my issue as well.

    var parent =Model.AncestorOrSelf(level);
  • lucuma 261 posts 563 karma points
    Oct 17, 2012 @ 20:51
    lucuma
    0

    Good call, I can't recall if that was just a typo on my part after trying a million things.  The wierd thing is that it all of a sudden stopped working locally but was fine on the server which I can't explain by that @..  

  • Jason 22 posts 41 karma points
    Oct 17, 2012 @ 21:28
    Jason
    0

    Exact same thing with me.  When you create a .cshtml script inside Umbraco and select on of the templates like navigation it will prepopulate the razor code for a generic navigation.  The snippet contains the @Model error along with others like no space between the ul, li tags and html.raw helpers.  So that is where in my code I had the @Model.

  • Andy Carlier 16 posts 74 karma points
    Oct 16, 2013 @ 15:02
    Andy Carlier
    0

    Thanks Jason.  Been pulling my hair out and it turned out to be the erroneous @ before Model.  Sometimes it's the little things.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 16, 2013 @ 15:27
    Dennis Aaen
    2

    Hi Andy,

    Yeah I have also been there by adding @ before Model and get an error.

    If work with Razor in a Umbraco version 4.x. Umbraco version 4 forgives you, if you add an @ before Model in if statements, but in v6  are not forgiven.

    So in razor in a v4 of Umbraco you can do this:

    @if(@Model.Name=="home"){ 
     
    <p>Thisis the homepage!</p>
    }
    @if(@Model.NodeTypeAlias=="TextPage"){
     
    <p>thisis a textpage</p>
    }else{
     <p>this ia NOT a textpage</
    p>
    }

    And in a v6 you have to do it like this:

    @if(Model.Name=="home"){ 
     
    <p>Thisis the homepage!</p>
    }
    @if(Model.NodeTypeAlias=="TextPage"){
     
    <p>thisis a textpage</p>
    }else{
     <p>this ia NOT a textpage</
    p>
    }

     In the first place you shouldn't have been allowed to write @ in the if statements before Model in version 4, but this is now enforced in Razor 2.0.

    I hope this was a good explanation of why you sometimes can write @Model in if statements and foreach loops and so on.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft