ninject / Ninject

the ninja of .net dependency injectors
http://ninject.org/
Other
2.68k stars 530 forks source link

newVersion="3.2.0.0" #396

Closed smarteez17 closed 1 year ago

smarteez17 commented 1 year ago

Hi there. Please can I get some help. I have version 3.2.0.0 in a prod env and as of this morning it stopped working.

{"message":"An error has occurred.","exceptionMessage":"An error occurred when trying to create a controller of type 'CompositeItemsController'. Make sure that the controller has a parameterless public constructor.","exceptionType":"System.InvalidOperationException","stackTrace":" at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()","innerException":{"message":"An error has occurred.","exceptionMessage":"Object reference not set to an instance of an object.","exceptionType":"System.NullReferenceException","stackTrace":" at WS_COMPITEMS.ContextProvider.CreateInstance(IContext context)\r\n at Ninject.Activation.Provider1.Create(IContext context)\r\n at Ninject.Activation.Context.ResolveInternal(Object scope)\r\n at Ninject.Activation.Context.Resolve()\r\n at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()\r\n at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source)\r\n at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext()\r\n at System.Linq.Buffer1..ctor(IEnumerable1 source)\r\n at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)\r\n at Ninject.Activation.Providers.StandardProvider.Create(IContext context)\r\n at Ninject.Activation.Context.ResolveInternal(Object scope)\r\n at Ninject.Activation.Context.Resolve()\r\n at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()\r\n at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source)\r\n at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext()\r\n at System.Linq.Buffer1..ctor(IEnumerable1 source)\r\n at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)\r\n at Ninject.Activation.Providers.StandardProvider.Create(IContext context)\r\n at Ninject.Activation.Context.ResolveInternal(Object scope)\r\n at Ninject.Activation.Context.Resolve()\r\n at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()\r\n at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source)\r\n at Ninject.ResolutionExtensions.TryGet[T](IEnumerable1 iterator)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)"}}

scott-xu commented 1 year ago

Can you please share the implementation of WS_COMPITEMS.ContextProvider.CreateInstance

smarteez17 commented 1 year ago

using WS_COMPITEMS.DAL; using Ninject.Activation; using System.Web;

 

namespace WS_COMPITEMS {     public class ContextProvider : Provider     {          protected override PromotionItemsContext CreateInstance(IContext context)         {             HttpContext ctx = HttpContext.Current;             string dc = ctx.Request.Cookies["dcShortCode"].Value;             string connStr = "";

 

            switch (dc.ToUpper())             {                 case "KZN":                     connStr = "KZN_PromoItemDb";                     break;                           case "EST":                              connStr = "EST_PromoItemDb";                     break;                          case "CPT":                             connStr = "CPT_PromoItemDb";                     break;                           case "LVD":                              connStr = "LVD_PromoItemDb";                     break;                           case "NTH":                              connStr = "NTH_PromoItemDb";                     break;                           case "STH":                              connStr = "STH_PromoItemDb";                     break;                 default:                     connStr = "CO_PromoItemDb";                     break;             }

            PromotionItemsContext promoDbContext = new PromotionItemsContext(connStr);

 

            return promoDbContext;         }     } }

scott-xu commented 1 year ago

What if dc is Null?

smarteez17 commented 1 year ago

Hi @scott-xu DC is never null as the user dc come from AD and a dropdown . This app has been working for years and as of this monring we getting this error