ServiceStack Razor ContentPage Works in Debug but not deployed - razor

I am trying a very simple contentpage at ~/View.cshtml that consists of
#inherits ViewPage
 #{
Layout = "SimpleLayout";
ViewBag.Title = "Title";
}
<div id="content-page">
<p>Test</p>
</div>
at ~/Views/Shared/SimpleLayout.cshtml is
<!DOCTYPE HTML>
<html>
<head>
<title>Simple Layout</title>
</head>
<body>
<div id="content">
#RenderBody()
</div>
</body>
</html>
In debug mode it works fine, but on deploy it then shows
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: CS0146: Circular base class dependency
involving 'RazorOutput.ViewPage' and 'RazorOutput.ViewPage'
I'm trying to follow the RockStars example as closely as possible, so don't have an idea of what's wrong. My service views work fine.
Any suggestions would be appreciated.
Update
When the name of the page is changed (e.g. NewPage.cshtml) then it will not work in Debug either, throwing the same exception.

In Web.Config, make sure that you have:
<compilation debug="false">
I was getting the same error, and this fixed it.

Setting compilation debug="false" as suggested above did not work for me.
I was having the same error running locally in IIS Express and found that if I added this to the web.config it would work:
<appSettings>
<add key="webPages:Enabled" value="false" />
</appSettings>
I found that setting in ServiceStack's RazorRockstar sample, after comparing it line by line with my own project to see why mine wasn't working.

I was receiving similar compilation errors when trying to render Razor pages. Check that your website's AppHost is inheriting from AppHostBase and not AppHostHttpListenerBase.

Related

CSS not loading after site URL changes

So, basically we changed our site URL from a big one to a rather small URL.
for example, www.example.com/portal/public/media/12345 to www.newsite.com/12345
After these changes I see that the css is not loading anymore, is there anything that I need to add/remove to my jsp files?
I am accessing the css in my JSP files like:
<link href="/resources/portal.css" rel="stylesheet" />
resources folder is under ther web/webroot folder.
Error Log:
WARN 31 Jan 2018 13:43:08,694 () [PageNotFound] - No mapping found for HTTP request with URI [/portal/public/media/portal/resources/portal.css;jsessionid=799088F1EB2D765BAF6B5AB0F62364FC.tcserver0] in DispatcherServlet with name 'portal'
In the chrome browser console I get the following error: GET newsite.com/portal/resources/… net::ERR_AB
Please help.
We ended up changing the mapping of the new site to www.example.com/portal instead of www.example.com/portal/public/media
That solved the issue.

AngularJS Error: [ng:areq] Argument 'MyController' is not a function, got undefined

I'm getting error with angular JS Error: [ng:areq] Argument 'MyController' is not a function, got undefined, when trying to use bundles. However when I explicity include the app in my html using script tags it works.
Bundle Config.cs
bundles.Add(new ScriptBundle("~/bundles/myweb")
.IncludeDirectory("~/Scripts/myweb", "*.js")
.IncludeDirectory("~/Scripts/myweb/Controllers", "*.js")
.Include("~/Scripts/myweb/Controllers/myController.js")
.Include("~/Scripts/myweb/myweb.js"));
With this HTML does not work:
<script src="~/Scripts/angular.js"></script>
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
#Scripts.Render("~/bundles/myweb")
This HTML does work but I'm unsure why I have to explicitly include myApp.js since it is already included in the bundle (and when I view the bundle from F12 - Developer Tools on Google Chrome it does already include the expected code):
<script src="~/Scripts/angular.js"></script>
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
#Scripts.Render("~/bundles/myweb")
<script src="~/Scripts/myweb/myweb.js"></script>
Note the shown html is in the head of _Layout.cshtml. I'm using angularJS with MVC.
Just figured out how to fix this.
I basically need to include the following code
<script src="~/Scripts/angular.js"></script>
#Scripts.Render("~/bundles/myweb")
in both the _Layout.cshtml and the index.cshtml (I only had it in Index.cshtml)

grails outputs "an error has occurred", how do I show the actual error?

In the bowels of my grails controllers or services, something is throwing an exception (I assume). The result is the web page just shows "an error has occurred", which is not much help.
The strange thing about grails is it seems to throw no exceptions, so I cant put try/catch and do something like log the error or send an explicit error message with stack trace to the user.
Any ideas how this can be done with grails? When I search, I only find info on displaying validation errors, unfortunately. I am sure there is an easy way!
As I have no idea what kind of exception is actually occurring, or why, I need to catch and display any exception with a stack trace.
OK, the answer was actually quite easy. You just have to create an error.gsp in the root of your views, with the following code (which will output the except no matter what env is there:
<!DOCTYPE html>
<html>
<head>
<title><g:if env="development">Grails Runtime Exception</g:if><g:else>Error</g:else></title>
<meta name="layout" content="main">
<g:if env="development"><link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css"></g:if>
</head>
<body>
<h2>Time: <g:formatDate format="yyyy-MM-dd hh:mm:ss" date="${new Date()}"/> </h2>
<g:renderException exception="${exception}" />
</body>
</html>

phpinfo() Expression Web 4

I've installed Microsoft Expression Web 4, installed php 5.3.28, renamed the php.ini-production to php.ini, did display_errors=on, did cgi.force_redirect=0, switched the positions of php_mbstring.dll and php_exif.dll (ran php.exe and it said it could not find php_mbstring.dll), directed expression web to the php-cgi.exe, and forced expression web 4 to boot a server for every test. I run the sample code for php information as follows...
file name - "index.php"
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled 1</title>
</head>
<body>
<?php
phpinfo() ;
?>
</body>
</html>
I get a blank page (WSOD), and am still looking for a solution.
In short I've been following the instructions given here.
And followed up with some additional potential fixes with little success.
Thank you in advance for your time.
Solved the problem, did a full reinstall of all products involved.

No highlighting in most pages, reports error when editing

I'm in the middle of upgrading a solution from VS2010/MVC3/.Net 4 to VS2012/MVC4/.Net 4.5. The solution has been upgraded using VS2012's project migration tool and I followed this guide to upgrade MVC3 to 4.
At the moment, Razor is giving me problems. Syntax highlighting doesn't appear for anything but the layout page, and when I try to move around in a view I either get the dialog:
Waiting for a background operation to complete. This dialog will close
when the operation completes.
Or I get an error telling me to check the Visual Studio activity log (C:\Users{User}\AppData\Roaming\Microsoft\VisualStudio\11.0\ActivityLog.xml), which led me to this error:
System.NullReferenceException: Object reference not set to an instance
of an object. at
Microsoft.VisualStudio.Web.HTML.Implementation.Projection.GrowingSpanTracker.EnsureNoOverlap()
at
Microsoft.VisualStudio.Web.HTML.Implementation.Projection.GrowingSpanTracker.EnsureTrackingPoints()
at
Microsoft.VisualStudio.Web.HTML.Implementation.Projection.GrowingSpanTracker.OnTextBufferChanged(Object
sender, TextContentChangedEventArgs e) at
Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent[TArgs](Object
sender, EventHandler`1 eventHandlers, TArgs args)
The Source column of the log says it comes from a "Editor or Editor Extension". I'm running vanilla VS2012 here, with no extensions aside from the first party stuff (Microsoft Web Developer Tools, NuGet Package Manager, and Visual Studio Extensions for Windows Library for JavaScript).
EDIT: Some additional details. If I create a new solution and MVC4 project, add the line:
#RenderSection("title", false)
to the layout, and then attempt to define the section in a view:
#section title{Stuff}
The moment I start typing "Stuff" within the braces I get the same errors/behavior.
Turns out whatever changed in Razor made braces a bit more...sensitive. If you have a section defined in your layout like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>#RenderSection("title", false) - MyApp</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
#RenderSection("css",false)
</head>
...
And then, in a view that uses the layout, try to use that section exactly like this (make sure you actually type it, don't copy/paste):
#model MyApp.Web.Models.HomeIndexModel
#section title {Lovely Title}
Razor will throw a fit and toss an error into your Visual Studio activity log. Highlighting and most Intellisense support will also fail to work. After some trial and error, I found that it works fine if you basically never leave the braces on the same line. So, write it like this:
#model MyApp.Web.Models.HomeIndexModel
#section title {
Lovely Title
}
And it will work fine.