0

Does any one know why autofac fails to initialize the mvc controllers when there is an applicaton in the root and also another in sub application in IIS? How to fix this?

When the apps are hosted in different Websites in IIS they work without a problem.enter image description here

so in the image, the root app(mvc web) deployed in the root works but not the webservice (mvc api).

error is

An error has occurred.An error occurred when trying to create a controller of type 'UserController'. Make sure that the controller has a parameterless public constructor.System.InvalidOperationException at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()An error has occurred.An exception was thrown while invoking the constructor 'Void .ctor()' on type 'BurpDaddyEntities'. ---> The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. (See inner exception for details.)Autofac.Core.DependencyResolutionException at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters)

Soori
  • 61
  • 5

1 Answers1

3

While the top-level exception appears to be from Autofac, if you look down at the inner exception issue that caused the whole thing, you'll see the true exception is The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. Which means the static constructor for that class went awry.

Fortunately, there's actually a question (with an answer!) directly about exactly what you're facing here with nested websites using Entity Framework: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception on a Sub Website

Community
  • 1
  • 1
Travis Illig
  • 23,195
  • 2
  • 62
  • 85
  • I know I am late to the party but its worth mentioning, in the article you provided, there is a section talking about clearing out the inherited configs. Doing that helped me. Thank you!!! – Soori Jul 06 '15 at 06:56