.net - Possible OWIN Startup and Ninject concurrent request issue ? -


i have created asp.net webapi .net framework 4.5. ninject 3.2.00 microsoft.owin 3.0.10

api deployed iis-7

our owin startup class looks :

public class startup {     public void configuration(iappbuilder app)     {         var config = globalconfiguration.configuration;          webapiconfig.register(config);         ninjectconfig.register(app, config);     } } 

and ninjectconfig.cs like

public class ninjectconfig {     public static void register(iappbuilder app, httpconfiguration config)     {         app.useninjectmiddleware(createkernel)             .useninjectwebapi(config);     }      private static ikernel createkernel()     {         var kernel = new standardkernel();          kernel.load("xyz.*.dll");          return kernel;     } } 

facing following error...

if @ least 2 simultaneous calls made api after apppool refresh, 1 of 2 simultaneous calls fails after second error , other succeeds after 3 seconds of startup. subsequent calls succeed, parallel or in sequence.

the problem not occur when single request made after recycling apppool

stacktrace:

{ "message":"an error has occurred.", "exceptionmessage":"an error occurred when trying create controller of type 'testcontroller'. make sure controller has parameterless public constructor.", "exceptiontype":"system.invalidoperationexception", "stacktrace":"   @ system.web.http.dispatcher.defaulthttpcontrolleractivator.create(httprequestmessage request,  httpcontrollerdescriptor controllerdescriptor,  type controllertype)\r\n   @ system.web.http.controllers.httpcontrollerdescriptor.createcontroller(httprequestmessage request)\r\n   @ system.web.http.dispatcher.httpcontrollerdispatcher.<sendasync>d__1.movenext()", "innerexception":{     "message":"an error has occurred.",     "exceptionmessage":"type 'test.xyz.api.controllers.testcontroller' not have default constructor",     "exceptiontype":"system.argumentexception",     "stacktrace":"   @ system.linq.expressions.expression.new(type type)\r\n   @ system.web.http.internal.typeactivator.create[tbase](type instancetype)\r\n   @ system.web.http.dispatcher.defaulthttpcontrolleractivator.getinstanceoractivator(httprequestmessage request,      type controllertype,      func`1& activator)\r\n   @ system.web.http.dispatcher.defaulthttpcontrolleractivator.create(httprequestmessage request,      httpcontrollerdescriptor controllerdescriptor,      type controllertype)" } 

we wondering if kind of concurrency issue while loading ninject dependencies. can issue be, or if there wrong our startup class ?

i fixed similar issue using code mentioned @ https://stackoverflow.com/a/35048937

ikernel kernel = createkernel();  app.useninjectmiddleware(() => kernel)             .useninjectwebapi(config); 

you can try above code in ninjectconfig.register()


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -