MVC System.Web.HttpCompileException on Html.Render

2019-06-17 08:59发布

I'm getting an System.Web.HttpCompileException when the my view calls Html.RederPartial. The exception message is:

Additional information: External component has thrown an exception.

I've checked that the:

  • Controller doesn't throw an exception
  • Partial view does exist
  • The Model passed by controller and received by the view is the same.
  • The InnerException is null

The exception sounds like it should be that the html or razor is malformed or incorrect, but the solution builds fine. It was also working not too long ago, so I'm guessing, I'm missing something silly...

My question:

Does anyone know how to know what causes this exception? Or is there a way to get more information on the exception?

Edit: Here's the StackTrace

at System.Web.Compilation.AssemblyBuilder.Compile() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean ...

2条回答
我想做一个坏孩纸
2楼-- · 2019-06-17 09:04

I found one of my HTML partial i.e. *.cshtml file was missing references. Generally when any cshtml page having error on it, is not shown at compile time though you can track it with debug points

查看更多
姐就是有狂的资本
3楼-- · 2019-06-17 09:09

Turns out it was a silly mistake on my part. MVC couldn't compile the Html from Razor because I had renamed a property within my Model, but didn't update it in the .cshtml.

Turn on Razor Build errors at compile time. Edit your csproj file and set the following:

<MvcBuildViews>true</MvcBuildViews>

Thanks to JP for this SO post.

查看更多
登录 后发表回答