新的环境,新的起点

今天是我新的工作岗位的第一天。

标签: 新工作

运行示例问题:“未将对象引用设置到对象的实例”

环境:Windows 2003 server, Sql Server 2005 Express
按照示例安装步骤,附加了数据库,修改了数据库连接字符串,新建了一个网站。
访问网站出现 “未将对象引用设置到对象的实例”错误。

主要原因应该是:
Error creating object with name 'RoleModuleManager' defined in 'assembly [FastSpring.Net.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=null], resource [FastSpring.Core.spring.net_bean_business.xml]' : Initialization of object failed : 未将对象引用设置到对象的实例。]

但查看了一下源码和配置又没有发现什么错误。
到底是什么原因引起的呢。
我之前在XP(数据库也是2005)上是安装成功的。


具体的错误信息如下:


“/FastSpring.Net.AppWeb”应用程序中的服务器错误。
--------------------------------------------------------------------------------

未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 

堆栈跟踪:


[NullReferenceException: 未将对象引用设置到对象的实例。]
  Spring.Data.NHibernate.HibernateAccessor.ConvertAdoAccessException(ADOException ex) +80
  Spring.Data.NHibernate.HibernateTemplate.Execute(IHibernateCallback action, Boolean exposeNativeSession) +415
  Spring.Data.NHibernate.HibernateTemplate.FindByNamedQuery(String queryName, Object[] values, IType[] types) +132
  Spring.Data.NHibernate.HibernateTemplate.FindByNamedQuery(String queryName) +34
  FastSpring.Base.BaseDAO.FindEntityListByNamedQuery(String QueryName) +33
  FastSpring.Core.BLL.RoleManager.GetAllRoles() +33
  FastSpring.Core.BLL.RoleModuleManager.Init() +29
  FastSpring.Core.BLL.RoleModuleManager.set_CacheRoleManager(ICacheRoleManager value) +35
  Spring.DynamicReflection.Property_CacheRoleManager_d2abe0d6d80940a190d30e1049d3f579.SetValue(Object target, Object value) +86
  Spring.Reflection.Dynamic.SafeProperty.SetValue(Object target, Object value) +558
  Spring.Expressions.PropertyValueAccessor.Set(Object context, Object value) +130
  Spring.Expressions.PropertyOrFieldNode.SetPropertyOrFieldValueInternal(Object context, Object newValue) +37
  Spring.Expressions.PropertyOrFieldNode.SetPropertyOrFieldValue(Object context, EvaluationContext evalContext, Object newValue) +563
  Spring.Expressions.PropertyOrFieldNode.Set(Object context, EvaluationContext evalContext, Object newValue) +223
  Spring.Expressions.BaseNode.SetValue(Object context, IDictionary variables, Object newValue) +68
  Spring.Expressions.BaseNode.Spring.Expressions.IExpression.SetValue(Object context, Object newValue) +34
  Spring.Objects.ObjectWrapper.SetPropertyValue(IExpression propertyExpression, Object val) +37
  Spring.Objects.ObjectWrapper.SetPropertyValue(PropertyValue pv) +59
  Spring.Objects.ObjectWrapper.SetPropertyValues(IPropertyValues propertyValues, Boolean ignoreUnknown) +675
  Spring.Objects.ObjectWrapper.SetPropertyValues(IPropertyValues pvs) +30
  Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ApplyPropertyValues(String name, RootObjectDefinition definition, IObjectWrapper wrapper, IPropertyValues properties) +344
  Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.PopulateObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) +976
  Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) +117
  Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) +675

[ObjectCreationException: Error creating object with name 'RoleModuleManager' defined in 'assembly [FastSpring.Net.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=null], resource [FastSpring.Core.spring.net_bean_business.xml]' : Initialization of object failed : 未将对象引用设置到对象的实例。]
  Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) +827
  Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments) +42
  Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) +191
  Spring.Objects.Factory.Support.WebObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) +123
  Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name, Type requiredType, Object[] arguments) +542
  Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) +57
  Spring.Objects.Factory.Support.DefaultListableObjectFactory.PreInstantiateSingletons() +538
  Spring.Context.Support.AbstractApplicationContext.Refresh() +691
  Spring.Context.Support.WebApplicationContext..ctor(String name, Boolean caseSensitive, IApplicationContext parentContext, String[] configurationLocations) +77
  Spring.Context.Support.WebApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) +41

[TargetInvocationException: 调用的目标发生了异常。]
  System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType) +0
  System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType) +13
  System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +366
  System.Reflection.ConstructorInfo.Invoke(Object[] parameters) +14
  Spring.Util.ObjectUtils.InstantiateType(ConstructorInfo constructor, Object[] arguments) +591

[FatalReflectionException: Cannot instantiate Type [Spring.Context.Support.WebApplicationContext] using ctor [Void .ctor(System.String, Boolean, System.String[])] : '调用的目标发生了异常。']
  Spring.Util.ObjectUtils.InstantiateType(ConstructorInfo constructor, Object[] arguments) +792
  Spring.Context.Support.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) +192
  Spring.Context.Support.ContextInstantiator.InstantiateContext() +147
  Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) +137
  Spring.Context.Support.WebContextHandler.InstantiateContext(IApplicationContext parent, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) +321
  Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) +426

[ConfigurationErrorsException: Error creating context '/fastspring.net.appweb': Error creating object with name 'RoleModuleManager' defined in 'assembly [FastSpring.Net.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=null], resource [FastSpring.Core.spring.net_bean_business.xml]' : Initialization of object failed : 未将对象引用设置到对象的实例。]
  System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +178
  System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) +896
  System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +1221
  System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission) +56
  System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +8
  System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) +65
  System.Configuration.ConfigurationManager.GetSection(String sectionName) +107
  Spring.Util.ConfigurationUtils.GetSection(String sectionName) +24
  Spring.Context.Support.WebApplicationContext.GetContextInternal(String virtualPath) +865
  Spring.Context.Support.WebApplicationContext.GetRootContext() +112
  Spring.Context.Support.WebSupportModule.Init(HttpApplication app) +386
  System.Web.HttpApplication.InitModulesCommon() +66
  System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +814
  System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +243
  System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +106
  System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +340

 

 

 

问题已解决,系数据库连接字符串的问题
在原有的字符串基础需增加一个参数Persist Security Info=True;
完整字符串为:
        <add key="DbProvider.ConnectionString" value="Data Source=CHANGHONG-JQM\SQLEXPRESS;Initial Catalog=FastSpring20;Persist Security Info=True;User ID=fastspring;Password=fastspring;Trusted_Connection=False"/>

标签: NHibernate Spring.NET C#