{"id":7362,"date":"2014-06-07T02:36:22","date_gmt":"2014-06-07T02:36:22","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/06\/07\/spring-net-object-reference-not-set-to-an-instance-of-an-object-collection-of-common-programming-errors\/"},"modified":"2014-06-07T02:36:22","modified_gmt":"2014-06-07T02:36:22","slug":"spring-net-object-reference-not-set-to-an-instance-of-an-object-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/06\/07\/spring-net-object-reference-not-set-to-an-instance-of-an-object-collection-of-common-programming-errors\/","title":{"rendered":"Spring.NET &#8211; Object reference not set to an instance of an object-Collection of common programming errors"},"content":{"rendered":"<p>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.<\/p>\n<p>The hibernate mapping is:<\/p>\n<pre><code>\n    \n        \n        \n        \n        \n        \n        \n        \n        \n        \n             \n        \n\n<\/code><\/pre>\n<p>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).<\/p>\n<p>Now the Web.config I have I have set spring as sectionGroup and defined it as:<\/p>\n<pre><code>\n    \n    \n    \n    \n    \n\n\n    \n    \n    \n    \n\n\n    \n\n<\/code><\/pre>\n<p>Also I have added <code>Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName<\/code> key in appsettings:<\/p>\n<pre><code>\n    \n\n<\/code><\/pre>\n<p>The httpModules of the system.web has the following entries:<\/p>\n<pre><code>\n    \n    \n\n<\/code><\/pre>\n<p>And lastly the spring resource Web.xml has the following objects:<\/p>\n<pre><code>\n    \n\n\n\n\n\n    \n    \n    \n        assembly:\/\/EMSApplication\/Domain\/EMSApplication.hbm.xml\n    \n    \n    \n    \n        \n        \n        \n        \n        \n        \n        \n    \n    \n\n    \n\n\n\n    \n    \n\n\n\n\n\n    \n\n\n\n<\/code><\/pre>\n<p>Now when I am starting debug from Visual Studio 2010 I am getting<\/p>\n<blockquote>\n<p>System.NullReferenceException: Object reference not set to an instance of an object.<\/p>\n<\/blockquote>\n<p>The complete stack trace is:<\/p>\n<pre><code>    [NullReferenceException: Object reference not set to an instance of an object.]\n   System.Xml.XmlReader.CalcBufferSize(Stream input) +14\n   System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding) +66\n   System.Xml.XmlTextReaderImpl..ctor(String url, Stream input, XmlNameTable nt) +93\n   System.Xml.XmlTextReader..ctor(Stream input) +74\n   NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in d:\\CSharp\\NH\\NH\\nhibernate\\src\\NHibernate\\Cfg\\Configuration.cs:631\n\n[MappingException: Could not configure datastore from input stream ]\n   NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in d:\\CSharp\\NH\\NH\\nhibernate\\src\\NHibernate\\Cfg\\Configuration.cs:342\n   NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in d:\\CSharp\\NH\\NH\\nhibernate\\src\\NHibernate\\Cfg\\Configuration.cs:641\n   NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream) in d:\\CSharp\\NH\\NH\\nhibernate\\src\\NHibernate\\Cfg\\Configuration.cs:611\n   Spring.Data.NHibernate.LocalSessionFactoryObject.AfterPropertiesSet() in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Data.NHibernate20\\Data\\NHibernate\\LocalSessionFactoryObject.cs:599\n   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\n   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\n   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\n   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\n\n[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 ]\n   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\n   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\n   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\n   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\n   Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Core\\Objects\\Factory\\Support\\AbstractObjectFactory.cs:1826\n   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\n   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\n   Spring.Dao.Support.PersistenceExceptionTranslationInterceptor.DetectPersistenceExceptionTranslators(IListableObjectFactory objectFactory) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Data\\Dao\\Support\\PersistenceExceptionTranslationInterceptor.cs:155\n   Spring.Dao.Support.PersistenceExceptionTranslationInterceptor..ctor(IListableObjectFactory objectFactory) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Data\\Dao\\Support\\PersistenceExceptionTranslationInterceptor.cs:73\n   Spring.Dao.Attributes.PersistenceExceptionTranslationAdvisor..ctor(IListableObjectFactory objectFactory, Type repositoryAttributeType) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Data\\Dao\\Attributes\\PersistenceExceptionTranslationAdvisor.cs:63\n   Spring.Dao.Attributes.PersistenceExceptionTranslationPostProcessor.set_ObjectFactory(IObjectFactory value) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Data\\Dao\\Attributes\\PersistenceExceptionTranslationPostProcessor.cs:95\n   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\n   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\n   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\n   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\n   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\n   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\n   Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Core\\Objects\\Factory\\Support\\AbstractObjectFactory.cs:1826\n   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\n   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\n   Spring.Context.Support.AbstractApplicationContext.RegisterObjectPostProcessors(IConfigurableListableObjectFactory objectFactory) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Core\\Context\\Support\\AbstractApplicationContext.cs:652\n   Spring.Context.Support.AbstractApplicationContext.Refresh() in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Core\\Context\\Support\\AbstractApplicationContext.cs:1000\n   Spring.Context.Support.WebApplicationContext..ctor(WebApplicationContextArgs args) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Web\\Context\\Support\\WebApplicationContext.cs:125\n   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\n   _dynamic_Spring.Context.Support.WebApplicationContext..ctor(Object[] ) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Web\\Caching\\AspNetCache.cs:126\n   Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] arguments) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Core\\Reflection\\Dynamic\\DynamicConstructor.cs:116\n   Spring.Context.Support.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Core\\Context\\Support\\ContextHandler.cs:563\n   Spring.Context.Support.ContextInstantiator.InstantiateContext() in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Core\\Context\\Support\\ContextHandler.cs:508\n   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\n   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\n   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\n\n[ConfigurationErrorsException: Error creating context 'spring.root': Could not configure datastore from input stream ]\n   System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +199\n   System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object&amp; result, Object&amp; resultRuntimeObject) +1153\n   System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject) +1468\n   System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +41\n   System.Web.HttpContext.GetSection(String sectionName) +52\n   System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) +57\n   System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) +6\n   System.Configuration.ConfigurationManager.GetSection(String sectionName) +78\n   Spring.Util.ConfigurationUtils.GetSection(String sectionName) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Core\\Util\\ConfigurationUtils.cs:71\n   Spring.Context.Support.WebApplicationContext.GetContextInternal(String virtualPath) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Web\\Context\\Support\\WebApplicationContext.cs:335\n   Spring.Context.Support.WebApplicationContext.GetRootContext() in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Web\\Context\\Support\\WebApplicationContext.cs:223\n   Spring.Context.Support.WebSupportModule.Init(HttpApplication app) in c:\\_prj\\spring-net\\trunk\\src\\Spring\\Spring.Web\\Context\\Support\\WebSupportModule.cs:175\n   System.Web.HttpApplication.InitModulesCommon() +172\n   System.Web.HttpApplication.InitModules() +43\n   System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +828\n   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +304\n   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107\n   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +327\n<\/code><\/pre>\n<p>Here as you can see:<\/p>\n<blockquote>\n<p>[ObjectCreationException: Error creating object with name &#8216;NHibernateSessionFactory&#8217; defined in &#8216;file [D:\\Code\\EMSApplication\\EMSApplication\\Web.xml] line 14&#8217; : Initialization of object failed : Could not configure datastore from input stream ]<\/p>\n<\/blockquote>\n<p>So I am unable to figure how to solve this problem. Any help or suggestion I really appreciate.<\/p>\n<p>Thank you.<\/p>\n<p>N.B.: I didn&#8217;t change any settings in IIS 7.<\/p>\n<p>Edit:<\/p>\n<p>These are the references used:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/Dy3jT.png\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7362","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7362"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7362\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}