NinjectMVC3 的 WebActivator.PreApplicationStartMethod 程序集属性在我的视图源编辑器中导致警告
在我的 Web 应用程序中使用 NinjectMVC3 的 WebActivator.PreApplicationStartMethod
属性时,
[assembly: WebActivator.PreApplicationStartMethod(typeof(MyProject.App_Start.NinjectMVC3), "Start")]
我在每个视图源编辑器文件中看到以下警告:
xxx.cshtml:ASP.NET运行时错误:预应用程序启动 初始化方法 Run on type WebActivator.ActivationManager 抛出 出现以下错误消息的异常:异常已 由调用目标抛出.. xxx.cshtml 1 1
它在我的每个视图文件的第一行上表现为蓝色波浪线(例如 @using
或 @model
声明)。请注意,应用程序运行得很好,问题仅出现在编辑我的视图源文件时(Visual Studio 实时错误/警告分析)。
我可以通过注释掉 WebActivator.PreApplicationStartMethod
来验证它是否是原因。
我该如何解决这个问题?
When using NinjectMVC3's WebActivator.PreApplicationStartMethod
attribute in my web application,
[assembly: WebActivator.PreApplicationStartMethod(typeof(MyProject.App_Start.NinjectMVC3), "Start")]
I am seeing the following warning in each of my view source editor files:
xxx.cshtml: ASP.NET runtime error: The pre-application start
initialization method Run on type WebActivator.ActivationManager threw
an exception with the following error message: Exception has been
thrown by the target of an invocation.. xxx.cshtml 1 1
it manifests itself as a blue-squiggly on the first line of each of my view files (e.g. a @using
or @model
declaration). Note that the application runs just fine, the problem is only while editing my view source files (visual studio real-time error / warning analysis).
I can verify that WebActivator.PreApplicationStartMethod
is the cause by commenting it out.
How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WebActivator 不是 Ninject 的组件,它由 Microsoft 提供,并由 MVC 团队的架构师 David Ebbo 维护。 Ninject 只是使用 WebActivator 自行安装,无需修改 global.asax。
显然您的某些配置不正确,因为这种情况不应该发生。您是否使用一些第三方编辑器,例如 Resharper 或 CodeRush?
确保您拥有最新版本的 WebActivator(使用 NuGet 进行更新)。另外,您还使用其他扩展吗?
我无法理解这如何影响您的设计时视图,因为此属性仅应在应用程序运行时生效。我唯一能想到的是第三方扩展在解析该行时被绊倒,并导致了问题。
尝试禁用所有扩展并查看问题是否仍然存在。
WebActivator is not a component of Ninject, it's provided by Microsoft, and maintained by David Ebbo, an architect on the MVC team. Ninject is just using WebActivator to install itself without having to modify global.asax.
Clearly you have some configuration incorrect as this should not be happening. Are you using some third party editor, like Resharper or CodeRush?
Make sure you have the latest version of WebActivator (use NuGet to update). Also, are you using any other extensions?
I can't understand how this can affect your design-time view, since this attribute should only take effect when the application is running. The only thing I can think of is that a third party extension is getting tripped up by parsing the line, and is causing the problem.
Try disabling all extensions and see if the problem remains.
我对此有点晚了,刚刚经历了这个......对我来说,这是因为我没有设置连接字符串。一旦我添加了它,错误就消失了。
I'm a little late to this, and just went through this... For me it was because I didn't have a connection string set up. Once I added it, things errors went away.