NinjectMVC3's WebActivator.PreApplicationStartMethod assembly attribute causing warnings in my view source editors

3k views Asked by At

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?

2

There are 2 answers

1
KellyTheDev On

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.

6
Erik Funkenbusch On

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.