开发者

Exception when using ninject

I have been trying to use the example in Asp.Net Pro MVC 2, chapter 3 where the author uses ninjet for Dependency injection, i have converted the code to vb.net since he uses c#, added the references but then when i tried to run the code i get an exception on

Return DirectCast(kernel.Get(controllerType), IController)

The exception is System.InvalidProgramException, yet when i use the author code with c# it works fine and passes that line successfully,

So can anyone help me please

here is the exception details:

[InvalidProgramException: Common Language Runtime detected an invalid program.]
   System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(IRuntimeMethodInfo method) +0
   System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType) +9574057
   Ninject.Injection.DynamicMethodInjectorFactory.Create(ConstructorInfo constructor) +504
   Ninject.Planning.Strategies.ConstructorReflectionStrategy.Execute(IPlan plan) +213
   Ninject.Planning.<>c__DisplayClass1.<GetPlan>b__0(IPlanningStrategy s) +40
   Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable`1 series, Action`1 action) +200
   Ninject.Planning.Planner.GetPlan(Type type) +246
   Ninject.Activation.Providers.StandardProvider.Create(IContext context) +223
   Ninject.Activation.Context.Resolve() +395
   Ninject.KernelBase.<Resolve>b__7(IContext context) +31
   System.Linq.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x) +32
 开发者_JAVA技巧  System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +151
   System.Linq.Enumerable.Single(IEnumerable`1 source) +196
   Ninject.ResolutionExtensions.Get(IResolutionRoot root, Type service, IParameter[] parameters) +62
   SportsStore.WebUI.NinjectControllerFactory.GetControllerInstance(RequestContext context, Type controllerType) in D:\Ahmad\VB Projects\SportsStore\SportsStore.WebUI\Infrastructure\NinjectControllerFactory.vb:14
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +204
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +193
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +160
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +80
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +45
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862676
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184


There is no reason why VB should behave diffrently. Are you sure you use the same code? Alternatively try to use Reflection based injection:

new StandardKernel(new NinjectSettings { UseReflectionBasedInjection = true })
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜