Exception when using ninject

I am trying to use an example in Asp.Net Pro MVC 2, chapter 3, where the author uses ninjet to inject dependencies, I converted the code to vb.net, since it uses C #, added links, but then when I tried to run the code, I get an exception in

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

The exception is System.InvalidProgramException, but when I use the author code with C #, it works fine and successfully passes this line,

So can someone help me?

here are the details of the exception:

 [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 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 
+4
source share
1 answer

There is no reason why a VB should behave differently. Are you sure you are using the same code? Alternatively try using reflection-based injection:

 new StandardKernel(new NinjectSettings { UseReflectionBasedInjection = true }) 
+2
source

All Articles