InterceptionExtention bug?

Topics: User Discussion
Jul 8, 2009 at 2:37 PM

Hi everyone!

I`m trying to use Unity and interception in MVC application.

I used source code from Mvc contrib to make container resolve mvc controtllers for me.

Then I used following code to configure container to configure interception of controllers and it also worked.

<font size="2">

global.AddNewExtension<

</font>

Interception>();

 

<font size="2">

global.Configure<Interception>.SetInterceptorFor(HomeController,

</font>

new VirtualMethodInterceptor());

Now I can intercept all virtual methods of HomeController. Thats fine.

But then I want to use dependency injection in my HomeController. And instead of empty default constructor I create following constructor:

public HomeController(IMyService service) {}

 

I configured container to know what is IMyService. When I try container.Resolve<IMyService>() it works fine.

But when I try to load the page in MVC application it throws exception:

 

[ArgumentNullException: Parameter can not be null
Parameter name: str]
   System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, String str) +7602986
   Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) +1051
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +119

[BuildFailedException: The current build operation (build key Build Key[OpenTest.Web.Controllers.CommunityController, null]) failed: Value can not be null.
Имя параметра: str (Strategy type DynamicMethodConstructorStrategy, index 0)]
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +349
   Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, Object buildKey) +199
   Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +216
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +119

[BuildFailedException: The current build operation (build key Build Key[OpenTest.Web.Controllers.CommunityController, null]) failed: The current build operation (build key Build Key[OpenTest.Web.Controllers.CommunityController, null]) failed: Значение не может быть неопределенным.
Имя параметра: str (Strategy type DynamicMethodConstructorStrategy, index 0) (Strategy type BuildPlanStrategy, index 5)]
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +349
   Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) +102
   Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) +217

[ResolutionFailedException: Resolution of the dependency failed, type = "OpenTest.Web.Controllers.CommunityController", name = "". Exception message is: The current build operation (build key Build Key[OpenTest.Web.Controllers.CommunityController, null]) failed: The current build operation (build key Build Key[OpenTest.Web.Controllers.CommunityController, null]) failed: Значение не может быть неопределенным.
Имя параметра: str (Strategy type DynamicMethodConstructorStrategy, index 0) (Strategy type BuildPlanStrategy, index 5)]
   Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) +277
   Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name) +42
   Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name) +40
   Microsoft.Practices.Unity.UnityContainerBase.Resolve(Type t) +41
   MvcContrib.Unity.UnityControllerFactory.CreateController(RequestContext context, String controllerName) in E:\Proj\opentest\MvcContrib.Unity\UnityControllerFactory.cs:21
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +128
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

 Some strings are localized but they generally say "Parameter str, value can no be null"

Coordinator
Sep 5, 2009 at 8:41 PM

Hi,

I am not sure this is the correct project for this question as it does not really relate to EntLib.  The Unity project might be a better place.

Cheers...   Steve