Razor 异常(exception)

标签 razor servicestack

我无疑设置了一些错误,但我的 Razor 模板经常抛出异常,即使模板没有问题。这些通常是通过我的构建来修复的。

如果我在模板中确实有错误,我会收到一个弹出窗口,要求我在 VS 中进行调试,但当然这实际上不允许我调试模板。

我的日志中的错误并没有多大帮助(见下文)。

是否可以在实际出现问题时既避免虚假错误又获得更好的信息?

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)

最佳答案

我遇到了类似的问题。我发现找出错误的“最简单”方法是下载所有服务堆栈,构建 razor 库的调试版本并将其链接到我的项目中。然后,我在 ServiceStack.Razor.Templating.TemplateService.CreateTemplate 方法中设置了一个断点,并且能够看到完整的异常详细信息。从那里我了解到我在我的 razor 页面中包含了我的项目中未引用的导入。

自从我解决了这个问题后,它一直非常可靠。

关于 Razor 异常(exception),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14748234/

相关文章:

c# - 在客户端处理自定义 ServiceStack 异常的正确/最佳方法是什么?

c# - ServiceStack - FluentValidation

servicestack - POST 到 ServiceStack 服务并检索位置 header

asp.net-core - 如何强制 Blazor 重新渲染组件

c# - 如何使用 Spotify API 将艺术家的名字添加到端点?

c# - 报告框架背后的基本原理

c# - 通过 Html.ActionLink 将输入参数传递给 Controller ​​方法

servicestack - 自定义 AspNetWindowsAuthProvider

.net-core - System.PlatformNotSupportedException : 'Operation is not supported on this platform.' when upgrading ServiceStack to .netcore 2.0

asp.net-mvc-4 - 未终止的字符串常量 MVC4 Razor View 引擎