Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor exceptions

I have undoubtedly set something up wrong but frequently I get exceptions thrown by my Razor templates even though there is no problem with the templates. These are usually fixed by my doing a build.

If I do actually have an error in the template I get a popup asking me to debug in VS, but of course this does not actually allow me to debug the template.

Errors in my log are not all that helpful (see below).

Is it possible to both avoid spurious errors and get better information when there is actually a problem?

ServiceStack.Razor.Templating.TemplateCompilationException: Unable to compile template. Check the Errors list for details.
   at ServiceStack.Razor.Templating.TemplateService.CreateTemplate(String template, Type modelType)
   at ServiceStack.Razor.Templating.TemplateService.Compile(ViewPageRef viewPageRef, String template, Type modelType, String name)
   at ServiceStack.Razor.Templating.TemplateService.Compile(ViewPageRef viewPageRef, String template, String name)
   at ServiceStack.Razor.ViewPageRef.Compile(Boolean force)
like image 320
David Churchland Avatar asked Jul 04 '26 17:07

David Churchland


2 Answers

I was having similar problems. I found the "easiest" way to find out what the error was, was to download all of service stack, build a debug version of the razor libary and link it into my project. I then set a break point in the ServiceStack.Razor.Templating.TemplateService.CreateTemplate method and was able to see the full exception details. From there I learnt that I had included an import in my razor page that was not referenced in my project.

Since I solved this it's been very reliable.

like image 85
MikeT Avatar answered Jul 10 '26 03:07

MikeT


I had trouble with this myself, because ServiceStack swallowed the exceptions, and the logs, as you said, don't show the Errors collection. There are two ways to get that information:

  1. Uncheck Enable Just My Code in the debugging options in Visual Studio (Debug -> Options and Settings). If you have checked Thrown for Common Language Runtime Exceptions in Debug -> Exceptions, you will get the exceptions, and be able to view the Errors collection.

  2. A merge was committed some days ago to the ServiceStack repository, which makes it log the Errors collection. Demis Bellot apparently pushes new versions to NuGet fairly often, so it'll probably be there in a week or two.

like image 40
dabide Avatar answered Jul 10 '26 03:07

dabide



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!