locked
IIS Compilation Question. Helpers not working. Custom Server RRS feed

  • Question

  • User-1416423428 posted

    Under my App_Code, I created a file.

    App_Code/Utilities.cshtml 

    @helper DisplayApple() { 
        <p>Apple!</p>
        }
    
    @helper DisplayOrange() { 
        <p>Orange!! ORange!!! </p>
        }
    
    @helper DisplayBanana() { 
        <p>Banana!!!!! Man!!!!</p>
    }
    

    Then in my footer, I call one of the helper functions

    <br />@Utilities.DisplayBanana()

    Running in VS2013, I hit "View in Browser" , and everything WORKS. 

    http://localhost:9999/default.cshtml 

    ....

    Now, if I right click on the Site Property, Start Options, and change it from "Use default Webserver" to "Use custom server", and then I enter my Base URL: http://mysite.mydomain.com and view the page, I get 

    <!--StartFragment-->Compiler Error Message: CS0117: 'ASP.Utilities' does not contain a definition for 'DisplayBanana'<!--EndFragment-->

    <!--StartFragment-->Source Error:

    Line 14:         @App.Copyright
    Line 15:         <br>Version: @App.Version - @App.LastModified
    Line 16:         <br />@Utilities.DisplayBanana()
    Line 17:       </div>
    Line 18:     </div>

    I mean.... just a few seconds ago, it executed the page properly. <!--EndFragment-->

    Now, the custom server is pointed to the same directory as the project. Everything seems to work there, code in _appStart, _pageStart, Layouts, RenderPage, RenderSection, etc... 

    Everything works except when I add a new @helper or @function (basically anything in App_Code), and the custom server doesn't seem to know things were changed. It tries to execute the c# code, but I get errors like above. (does not contain a definition for .....) 

    If I switch back to "Local Server", it works again. So there's nothing wrong with the code.

    But there seems to be something I'm missing when I use "Custom Server", it seems IIS 7.5 doesn't know that files have been changed, and it didn't recompile the site... and spitting an error on the helper function it doesn't know about.  If I remove the @helper function in my html page, it executes just fine.  

    The Application Pool is .NET Framework v4.0.30319, Integrated. I tried stopping, restarting -- no change. Didn't recompile. 

    I tried Restarting the website too, and no change. 

    In Application Log, I see this

    Log Name: Application Source: IIS Express Date: 5/23/2014 2:31:32 PM Event ID: 2264 Task Category: None Level: Warning Keywords: Classic User: N/A Computer: Win7 Description: The directory specified for caching compressed content C:\Users\ERINAK~1\AppData\Local\Temp\iisexpress\IIS Temporary Compressed Files\Clr4IntegratedAppPool is invalid. Static compression is being disabled. Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="IIS Express" /> <EventID Qualifiers="32768">2264</EventID> <Level>3</Level> <Task>0</Task> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2014-05-23T19:31:32.000000000Z" /> <EventRecordID>17853</EventRecordID> <Channel>Application</Channel> <Computer>Win7</Computer> <Security /> </System> <EventData> <Data>C:\Users\ERINAK~1\AppData\Local\Temp\iisexpress\IIS Temporary Compressed Files\Clr4IntegratedAppPool</Data> <Binary>03000000</Binary> </EventData> </Event>

    Is this even related? 

    I tried rebuilding the site by DEBUG > BUILD SITE, and still same error (does not contain a definition for ....) 

    Any tips?

    Friday, May 23, 2014 3:49 PM

Answers

All replies

  • User-1416423428 posted

    Update: It's definitely related to .NET Compilation in IIS. 

    If I toggle IIS > .NET Compilation > Batch Compilations from True to False, or from False to True, it seems IIS does a recompile behind the scenes and then the newly added @helper functions are recognized.  

    I thought IIS is supposed to recompile everything automatically if it detects a code source change in any of the subdirectories?

    Friday, May 23, 2014 4:06 PM
  • User938738290 posted

    What happens if you DEBUG -> Start Debugging with the default server, rather than using the View in Browser option?  Unfortunately, I don't have VS set up to debug on a remote server (Yet.  Now that I know it's an option, it seems super useful.  Can it connect to IIS 6.0?), so I can't reproduce your problem.

    EDIT: Never mind, if you were able to jog the server into recompiling, and that fixed the issue, that's it then.  I do not know of the existence of any force recompile option, though, sorry.

    Friday, May 23, 2014 4:07 PM
  • User-1416423428 posted

    YAY! SOLVED! 

    Add this to web.config, under <system.web>

      <system.web>
        <compilation batch="true" debug="true" tempDirectory="C:\temp" targetFramework="4.5" optimizeCompilations="true">
      </system.web>

    optimizeCompilations default is False. 

    I changed it to opimizeCompilations=True and now, whenever I make changes to helper files in App_Code, IIS recompiles automatically and no more errors! 

    Reference to MSDN article. 

    http://msdn.microsoft.com/en-us/library/vstudio/s10awwz0(v=vs.100).aspx

    Understanding ASP.NET Dynamic Compilation

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 23, 2014 4:35 PM