Nancy, First razor page not working

2019-05-06 06:03发布

I'm trying to get a first Razor template working with Nancy, and the first line of my .cshtml...

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>

gives me 3 build errors including the following...

'NancyContext' does not contain a definition for 'ApplicationInstance' and no extension method 'ApplicationInstance' accepting a first argument of type 'NancyContext' could be found (are you missing a using directive or an assembly reference?)

One very weird thing is that I have three "errors", but they're not stopping the build. They show in the Error list, the classes are underlined in red in the Solution explorer but not in the code window. Don't believe me ? Screenshot follows... enter image description here

Update

I've fixed the first two errors by adding explicit references to System.Web.Helpers and System.Web.WebPages. The remaining error, 'NancyContext' does not contain a definition for 'ApplicationInstance', is still bugging me. ApplicationInstance is a type in System.Web, for which I have a reference. If I delete the System.Web reference the project still builds. If I add the reference I still have the error.

标签: razor nancy
2条回答
疯言疯语
2楼-- · 2019-05-06 06:53

I got the same error today and then noticed that the project was getting build in "Build + IntelliSense" mode (as in your screenshot), going to the dropdown their and building in "Build Only" mode resolved my errors!

查看更多
乱世女痞
3楼-- · 2019-05-06 06:56

All I can say is that ApplicationInstance is not a Nancy type. Perhaps you are missing a namespace or assembly include? https://github.com/NancyFx/Nancy/wiki/Razor-View-Engine

Other than that, you are going to have to share a lot more information or there's not much to go on

查看更多
登录 后发表回答