Spring.NET – Object reference not set to an instance of an object-Collection of common programming errors

I am new in .NET. I have used Spring Framework and Hibernate before in Java, but this is my first in .NET. To develop my application I am using Spring.Northwind solution as example.

The hibernate mapping is:


    
        
        
        
        
        
        
        
        
        
             
        

As you can see the class Employee only has three field. It implements IEmployee which consists the definition of the get and set methods of these fields(If you want to see these classes I can provide).

Now the Web.config I have I have set spring as sectionGroup and defined it as:


    
    
    
    
    


    
    
    
    


    

Also I have added Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName key in appsettings:


    

The httpModules of the system.web has the following entries:


    
    

And lastly the spring resource Web.xml has the following objects:


    





    
    
    
        assembly://EMSApplication/Domain/EMSApplication.hbm.xml
    
    
    
    
        
        
        
        
        
        
        
    
    

    



    
    





    



Now when I am starting debug from Visual Studio 2010 I am getting

System.NullReferenceException: Object reference not set to an instance of an object.

The complete stack trace is:

    [NullReferenceException: Object reference not set to an instance of an object.]
   System.Xml.XmlReader.CalcBufferSize(Stream input) +14
   System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding) +66
   System.Xml.XmlTextReaderImpl..ctor(String url, Stream input, XmlNameTable nt) +93
   System.Xml.XmlTextReader..ctor(Stream input) +74
   NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:631

[MappingException: Could not configure datastore from input stream ]
   NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:342
   NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:641
   NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:611
   Spring.Data.NHibernate.LocalSessionFactoryObject.AfterPropertiesSet() in c:\_prj\spring-net\trunk\src\Spring\Spring.Data.NHibernate20\Data\NHibernate\LocalSessionFactoryObject.cs:599
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:1294
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:1890
   Spring.Objects.Factory.Support.WebObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Objects\Factory\Support\WebObjectFactory.cs:450
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:921

[ObjectCreationException: Error creating object with name 'NHibernateSessionFactory' defined in 'file [D:\Code\EMSApplication\EMSApplication\Web.xml] line 14' : Initialization of object failed : Could not configure datastore from input stream ]
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:938
   Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:2144
   Spring.Objects.Factory.Support.WebObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Objects\Factory\Support\WebObjectFactory.cs:299
   Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:2065
   Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:1826
   Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs:770
   Spring.Objects.Factory.ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(IListableObjectFactory factory, Type type, Boolean includePrototypes, Boolean includeFactoryObjects) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\ObjectFactoryUtils.cs:268
   Spring.Dao.Support.PersistenceExceptionTranslationInterceptor.DetectPersistenceExceptionTranslators(IListableObjectFactory objectFactory) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Dao\Support\PersistenceExceptionTranslationInterceptor.cs:155
   Spring.Dao.Support.PersistenceExceptionTranslationInterceptor..ctor(IListableObjectFactory objectFactory) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Dao\Support\PersistenceExceptionTranslationInterceptor.cs:73
   Spring.Dao.Attributes.PersistenceExceptionTranslationAdvisor..ctor(IListableObjectFactory objectFactory, Type repositoryAttributeType) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Dao\Attributes\PersistenceExceptionTranslationAdvisor.cs:63
   Spring.Dao.Attributes.PersistenceExceptionTranslationPostProcessor.set_ObjectFactory(IObjectFactory value) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Dao\Attributes\PersistenceExceptionTranslationPostProcessor.cs:95
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:1886
   Spring.Objects.Factory.Support.WebObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Objects\Factory\Support\WebObjectFactory.cs:450
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:930
   Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:2144
   Spring.Objects.Factory.Support.WebObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Objects\Factory\Support\WebObjectFactory.cs:299
   Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:2065
   Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:1826
   Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs:770
   Spring.Context.Support.AbstractApplicationContext.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:1383
   Spring.Context.Support.AbstractApplicationContext.RegisterObjectPostProcessors(IConfigurableListableObjectFactory objectFactory) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:652
   Spring.Context.Support.AbstractApplicationContext.Refresh() in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:1000
   Spring.Context.Support.WebApplicationContext..ctor(WebApplicationContextArgs args) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:125
   Spring.Context.Support.WebApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:82
   _dynamic_Spring.Context.Support.WebApplicationContext..ctor(Object[] ) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Caching\AspNetCache.cs:126
   Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Reflection\Dynamic\DynamicConstructor.cs:116
   Spring.Context.Support.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:563
   Spring.Context.Support.ContextInstantiator.InstantiateContext() in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:508
   Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:351
   Spring.Context.Support.WebContextHandler.InstantiateContext(IApplicationContext parent, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebContextHandler.cs:127
   Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:289

[ConfigurationErrorsException: Error creating context 'spring.root': Could not configure datastore from input stream ]
   System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +199
   System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) +1153
   System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +1468
   System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +41
   System.Web.HttpContext.GetSection(String sectionName) +52
   System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) +57
   System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) +6
   System.Configuration.ConfigurationManager.GetSection(String sectionName) +78
   Spring.Util.ConfigurationUtils.GetSection(String sectionName) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Util\ConfigurationUtils.cs:71
   Spring.Context.Support.WebApplicationContext.GetContextInternal(String virtualPath) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:335
   Spring.Context.Support.WebApplicationContext.GetRootContext() in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:223
   Spring.Context.Support.WebSupportModule.Init(HttpApplication app) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebSupportModule.cs:175
   System.Web.HttpApplication.InitModulesCommon() +172
   System.Web.HttpApplication.InitModules() +43
   System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +828
   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +304
   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +327

Here as you can see:

[ObjectCreationException: Error creating object with name ‘NHibernateSessionFactory’ defined in ‘file [D:\Code\EMSApplication\EMSApplication\Web.xml] line 14’ : Initialization of object failed : Could not configure datastore from input stream ]

So I am unable to figure how to solve this problem. Any help or suggestion I really appreciate.

Thank you.

N.B.: I didn’t change any settings in IIS 7.

Edit:

These are the references used: