i getting error in mvc application when trying create connection. i'm using nhibenate along ninject.
  global.asax.cs file:
  namespace web.ui {     public class mvcapplication : ninjecthttpapplication // system.web.httpapplication     {         public static isessionfactory sessionfactory { get; set; }          public void createsessionfactory()         {             sessionfactory = (new configuration()).configure().buildsessionfactory();         }          public static void registerroutes(routecollection routes)         {             routes.ignoreroute("{resource}.axd/{*pathinfo}");              routes.maproute(                 "default", // route name                 "{controller}/{action}/{id}", // url parameters                 new { controller = "home", action = "index", id = urlparameter.optional } // parameter defaults             );         }          protected override ikernel createkernel()         {             return new standardkernel(new mvcapplicationmodule());         }          protected override void onapplicationstarted()         {             registerroutes(routetable.routes);         }          protected override void onapplicationstopped()         {             sessionfactory.dispose();         }          protected void application_beginrequest()         {             var sessionfactory = sessionfactory.opensession();             currentsessioncontext.bind(sessionfactory);         }          protected void application_endrequest()         {             currentsessioncontext.unbind(sessionfactory);         }     }      internal class mvcapplicationmodule : ninjectmodule     {         public override void load()         {              // nhibernate session             bind<isession>().tomethod(ctx => mvcapplication.sessionfactory.getcurrentsession());              bind<imanagerrepository>().to<managerrepositoryimpl>();         }     } } 
  web.config file:
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">     <session-factory>       <!--       <property name="connection.provider">nhibernate.connection.driverconnectionprovider</property>       -->       <property name="connection.driver_class">nhibernate.driver.mysqldatadriver</property>       <property name="dialect">nhibernate.dialect.mysql5dialect</property>       <property name="connection.connection_string_name">myconnstring</property>       <property name="proxyfactory.factory_class">nhibernate.bytecode.castle.proxyfactoryfactory,nhibernate.bytecode.castle</property>       <property name="current_session_context_class">web</property>       <mapping assembly="infrastructure"/>     </session-factory>   </hibernate-configuration> 
  this error message:
  server error in '/' application. object reference not set instance of object. description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.  exception details: system.nullreferenceexception: object reference not set instance of object.  source error:  line 57:         protected void application_beginrequest() line 58:         { line 59:             var sessionfactory = sessionfactory.opensession(); line 60:             currentsessioncontext.bind(sessionfactory); line 61:         }  stack trace:  [nullreferenceexception: object reference not set instance of object.]    web.ui.mvcapplication.application_beginrequest()  [targetinvocationexception: exception has been thrown target of invocation.]    system.runtimemethodhandle._invokemethodfast(object target, object[] arguments, signaturestruct& sig, methodattributes methodattributes, runtimetypehandle typeowner) +0    system.runtimemethodhandle.invokemethodfast(object target, object[] arguments, signature sig, methodattributes methodattributes, runtimetypehandle typeowner) +71    system.reflection.runtimemethodinfo.invoke(object obj, bindingflags invokeattr, binder binder, object[] parameters, cultureinfo culture, boolean skipvisibilitychecks) +350    system.reflection.runtimemethodinfo.invoke(object obj, bindingflags invokeattr, binder binder, object[] parameters, cultureinfo culture) +29    system.web.util.arglesseventhandlerproxy.callback(object sender, eventargs e) +42    system.web.synceventexecutionstep.system.web.httpapplication.iexecutionstep.execute() +68    system.web.httpapplication.executestep(iexecutionstep step, boolean& completedsynchronously) +75   version information: microsoft .net framework version:2.0.50727.3053; asp.net version:2.0.50727.3053  
        
  global.asax.cs
  protected override void onapplicationstarted() {     registerroutes(routetable.routes);     createsessionfactory(); } 
       
   
Comments
Post a Comment