Search code examples
c#asp.net-mvc-3razorgenerator

Code generated by RazorGenerator not executed, script code still is


So I installed RazorGenerator with nuGet and added the VS extension (thanks to Visual Studio cannot find custom tool RazorGenerator).

Just to try it out on my existing mvc app, I changed the custom tool to RazorGenerator on one of the views, and generated the code with the right-click option "Run Custom Tool". The code was indeed created.

I then build the entire app and tried running it, setting a break point in both the old razor script and the new pre-compiled code. Much to my surprise, it was still running the old script code, not the new. Am I missing a step somewhere to switch over execution to the new code. The documentation is a little skimpy, but you would think something crucial like this would have been mentioned if needed. I know it calls the bootstrap code in App_Start using WebActivatorEx.PostApplicationStartMethod(), or at least it did so once, doesn't seem to do it on every debug start though, not even after an iisreset. If I try to delete the source razor view the ajax call fails when returning result, so it is obviously not using the precompiled code. Am I missing a step somewhere?

One thing I notice is that when I place a breakpoint in the Excecute() method in the generated code, it tells me "Breakpoint will not currently be hit. No executable code of the debugger's target code is associated with that line. Is the right code being generated?

#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace ASP
{
    using System;
    using System.Collections.Generic;

    #line 2 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
    using System.Data;

    #line default
    #line hidden
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Web;
    using System.Web.Helpers;
    using System.Web.Mvc;
    using System.Web.Mvc.Ajax;
    using System.Web.Mvc.Html;
    using System.Web.Routing;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.WebPages;

    #line 3 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
    using Core.Models.Organization.Table;

    #line default
    #line hidden

    #line 4 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
    using Core.ViewModels.Base;

    #line default
    #line hidden

    [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")]
    [System.Web.WebPages.PageVirtualPathAttribute("~/Areas/Views/GenericTable/DataCurrent.cshtml")]
    public partial class _Areas_Views_GenericTable_DataCurrent_cshtml : System.Web.Mvc.WebViewPage<GenericTableDataCurrent>
    {
        public _Areas_Views_GenericTable_DataCurrent_cshtml()
        {
        }
        public override void Execute()
        {
WriteLiteral("\r\n");


            #line 6 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"

    Response.ContentType = "text/xml";
    Layout = null;


            #line default
            #line hidden
WriteLiteral("\r\n<rows");

WriteAttribute("total_count", Tuple.Create(" total_count=\"", 240), Tuple.Create("\"", 271)

            #line 10 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
, Tuple.Create(Tuple.Create("", 254), Tuple.Create<System.Object, System.Int32>(Model.TotalCount

            #line default
            #line hidden
, 254), false)
);

WriteAttribute("pos", Tuple.Create(" pos=\"", 272), Tuple.Create("\"", 293)

            #line 10 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
, Tuple.Create(Tuple.Create("", 278), Tuple.Create<System.Object, System.Int32>(Model.Position

            #line default
            #line hidden
, 278), false)
);

WriteLiteral(">\r\n    <userdata");

WriteLiteral(" name=\"!ViewChanged\"");

WriteLiteral(">");


            #line 11 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                              Write((Model.ViewChanged.ToString()));


            #line default
            #line hidden
WriteLiteral("</userdata>\r\n    <userdata");

WriteLiteral(" name=\"!ViewSortColumn\"");

WriteLiteral(">");


            #line 12 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                                 Write((!string.IsNullOrEmpty(Model.ViewSortColumn) ? Model.ViewSortColumn : ""));


            #line default
            #line hidden
WriteLiteral("</userdata>\r\n    <userdata");

WriteLiteral(" name=\"!ViewSortDirection\"");

WriteLiteral(">");


            #line 13 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                                    Write((!string.IsNullOrEmpty(Model.ViewSortDirection) ? Model.ViewSortDirection : ""));


            #line default
            #line hidden
WriteLiteral("</userdata>\r\n    <userdata");

WriteLiteral(" name=\"!ViewError\"");

WriteLiteral(">");


            #line 14 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                            Write((!string.IsNullOrEmpty(Model.ViewError) ? Model.ViewError : ""));


            #line default
            #line hidden
WriteLiteral("</userdata>\r\n    <userdata");

WriteLiteral(" name=\"!CriteriaError\"");

WriteLiteral(">");


            #line 15 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                                Write((!string.IsNullOrEmpty(Model.CriteriaError) ? Model.CriteriaError : ""));


            #line default
            #line hidden
WriteLiteral("</userdata> \r\n    <userdata");

WriteLiteral(" name=\"!FilterError\"");

WriteLiteral(">");


            #line 16 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                              Write((!string.IsNullOrEmpty(Model.FilterError) ? Model.FilterError : ""));


            #line default
            #line hidden
WriteLiteral("</userdata>      \r\n");


            #line 17 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"


            #line default
            #line hidden

            #line 17 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
     foreach (DataRow drRow in Model.GenericTableTable.Rows)
    { 


            #line default
            #line hidden
WriteLiteral("    <row");

WriteAttribute("id", Tuple.Create(" id=\"", 1074), Tuple.Create("\"", 1116)

            #line 19 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
, Tuple.Create(Tuple.Create("", 1079), Tuple.Create<System.Object, System.Int32>(drRow[Model.Table +"^ID"].ToString()

            #line default
            #line hidden
, 1079), false)
);

WriteLiteral(" RowChangeState=\"0\"");

WriteLiteral(">\r\n");


            #line 20 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"


            #line default
            #line hidden

            #line 20 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
         foreach (PSIMColumn oPSIMColumn in Model.GenericTableDataColumns.AllColumns)
        {
            switch (oPSIMColumn.PSIMTable.Name.ToUpper())
            {
                case "MOC":


            #line default
            #line hidden
WriteLiteral("                    <cell />\r\n");


            #line 26 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                    break;
                default:


            #line default
            #line hidden
WriteLiteral("                    <cell ");


            #line 28 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                     Write(MvcHtmlString.Create(Model.GetCellAttributes(oPSIMColumn, drRow)));


            #line default
            #line hidden
WriteLiteral("><![CDATA[");


            #line 28 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                                                                                                 Write(Html.Raw(Model.CellValue(oPSIMColumn, drRow)));


            #line default
            #line hidden
WriteLiteral("]]></cell>\r\n");


            #line 29 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
                      break;
            }
        }


            #line default
            #line hidden
WriteLiteral("    </row>\r\n");


            #line 33 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
    }  


            #line default
            #line hidden
WriteLiteral("</rows>\r\n");

        }
    }
}
#pragma warning restore 1591

Solution

  • The road to a solution to this issue can be found here https://github.com/RazorGenerator/RazorGenerator/issues/94#issuecomment-220097861, it seems to have been rooted in problems with version discrepancies. Things seem to be working after moving solution to mvc 4 and webpages 2. Scrubbed all references and web.config files in all projects to make sure they lined up, uninstalled and reinstalled all nuGet packages. I am also using the source directly in a project, not installed as a dll from nuGet, since there seemed to be some version mismatch when installing from nuGet. I am placing this solution here in case others run into the same issues as me.