[ResolutionFailedException: Resolution of the dependency failed, type = "Umbraco.Web.Mvc.RenderMvcController", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type UmbracoContext does not have an accessible constructor.
[InvalidOperationException: An error occurred when trying to create a controller of type 'Umbraco.Web.Mvc.RenderMvcController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +240
Umbraco.Web.Mvc.UmbracoControllerFactory.CreateController(RequestContext requestContext, String controllerName) in c:\projects\umbraco-cms-xtjqd\src\Umbraco.Web\Mvc\UmbracoControllerFactory.cs:38
Umbraco.Web.Mvc.RenderControllerFactory.CreateController(RequestContext requestContext, String controllerName) in c:\projects\umbraco-cms-xtjqd\src\Umbraco.Web\Mvc\RenderControllerFactory.cs:37
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +268
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +95
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +1204
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +196
That basic registration should work for the Umbraco part...
container = new UnityContainer();
container.RegisterType<UmbracoContext>(
new HierarchicalLifetimeManager(),
new InjectionFactory(c => UmbracoContext.Current));
container.RegisterType<HealthCheckController>(new InjectionConstructor());
// MVC Configuration
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
// Web API Configuration
GlobalConfiguration.Configuration.DependencyResolver = new UnityWebApi.UnityDependencyResolver(container);
For every issue you need to know what do you need to inject. I didn't got that one but should be solved by registering how the object that gave the error is constructed. IPublishedContent should come from your current request, and is the current page requested.
What is the scope of that injection process because your umbracocontext.current should not be null if you are in the scope of a webrequest handled by umbraco.
You should also register your unity configuration in the OnApplicationStarting, and not OnApplicationStarted.
Umbraco 7.5.10 and Unity accessible constructor error
Hi all,
I'm having a bit of an issue setting up Unity to work with Umbraco 7.5.10.
I have set up Unity with a bog standard MVC app and it works great so I'm guessing that it's a Umbraco step that I've missed out.
After installing Unity and Unity.MVC packages via nuget I've restarted the application and and an getting the following error...
I have tried to register the Umbraco Context in both the UnityConfig.cs and the Global.aspx files using the following line...
Any help or advice on this issue would be a great help thanks in advance.
Kris
Here's the error stack trace...
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForNullExistingObject(IBuilderContext context) +226 lambdamethod(Closure , IBuilderContext ) +39 Microsoft.Practices.ObjectBuilder2.<>cDisplayClass1.0(IBuilderContext context) +33 Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +337 Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +396 Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +130 lambdamethod(Closure , IBuilderContext ) +208 Microsoft.Practices.ObjectBuilder2.<>cDisplayClass1.0(IBuilderContext context) +33 Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +337 Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +396 Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +238
[ResolutionFailedException: Resolution of the dependency failed, type = "Umbraco.Web.Mvc.RenderMvcController", name = "(none)". Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type UmbracoContext does not have an accessible constructor.
At the time of the exception, the container was:
Resolving Umbraco.Web.Mvc.RenderMvcController,(none) Resolving parameter "umbracoContext" of constructor Umbraco.Web.Mvc.RenderMvcController(Umbraco.Web.UmbracoContext umbracoContext, Umbraco.Web.UmbracoHelper umbracoHelper) Resolving Umbraco.Web.UmbracoContext,(none) ] Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +500 Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) +20 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +59
[InvalidOperationException: An error occurred when trying to create a controller of type 'Umbraco.Web.Mvc.RenderMvcController'. Make sure that the controller has a parameterless public constructor.] System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +240 Umbraco.Web.Mvc.UmbracoControllerFactory.CreateController(RequestContext requestContext, String controllerName) in c:\projects\umbraco-cms-xtjqd\src\Umbraco.Web\Mvc\UmbracoControllerFactory.cs:38 Umbraco.Web.Mvc.RenderControllerFactory.CreateController(RequestContext requestContext, String controllerName) in c:\projects\umbraco-cms-xtjqd\src\Umbraco.Web\Mvc\RenderControllerFactory.cs:37 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +268 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +95 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +1204 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +196
That basic registration should work for the Umbraco part...
Thanks For your response Laurent.
This code has definitely progressed the issue but I'm getting another error now.
Just to check that the code you pasted above was in the UnityConfig.cs class?
Just to add the UmbracoContext.Current is null.
Kris
Kris,
For every issue you need to know what do you need to inject. I didn't got that one but should be solved by registering how the object that gave the error is constructed. IPublishedContent should come from your current request, and is the current page requested.
What is the scope of that injection process because your umbracocontext.current should not be null if you are in the scope of a webrequest handled by umbraco.
You should also register your unity configuration in the OnApplicationStarting, and not OnApplicationStarted.
is working on a reply...