求教!ibatis.net中出现未将对象引用设置到对象的实例的错误(弄了好久了)
“/”应用程序中的服务器错误。--------------------------------------------------------------------------------
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 34:
行 35: DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
行 36: builder.ConfigureAndWatch("dao.config", handler);
行 37:
行 38: _instance = new ServiceConfig();
源文件: D:\VSS\HealthWeb\Health\SinoSoft.Health.Service\ServiceConfig.cs 行: 36
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
IBatisNet.DataMapper.Configuration.DomSqlMapBuilder.ConfigureSqlMap() +614
IBatisNet.DataMapper.Configuration.DomSqlMapBuilder.Initialize() +4685
IBatisNet.DataMapper.Configuration.DomSqlMapBuilder.Build(XmlDocument document, DataSource dataSource, Boolean useConfigFileWatcher, Boolean isCallFromDao) +233
[ConfigurationException:
- The error occurred while loading SqlMap.
- The error occurred in <sqlMap resource="Maps/Hb001Family.xml" xmlns="http://ibatis.apache.org/dataMapper" />.]
IBatisNet.DataMapper.Configuration.DomSqlMapBuilder.Build(XmlDocument document, DataSource dataSource, Boolean useConfigFileWatcher, Boolean isCallFromDao) +287
IBatisNet.DataMapper.Configuration.DomSqlMapBuilder.Build(XmlDocument document, DataSource dataSource, Boolean useConfigFileWatcher, NameValueCollection properties) +45
IBatisNet.DataAccess.DaoSessionHandlers.SqlMapDaoSessionHandler.Configure(NameValueCollection properties, IDictionary resources) +528
[ConfigurationException: DaoManager could not configure SqlMapDaoSessionHandler.Cause:
- The error occurred while loading SqlMap.
- The error occurred in <sqlMap resource="Maps/Hb001Family.xml" xmlns="http://ibatis.apache.org/dataMapper" />.]
IBatisNet.DataAccess.DaoSessionHandlers.SqlMapDaoSessionHandler.Configure(NameValueCollection properties, IDictionary resources) +610
IBatisNet.DataAccess.Configuration.DomDaoManagerBuilder.GetContexts(ConfigurationScope configurationScope) +1277
IBatisNet.DataAccess.Configuration.DomDaoManagerBuilder.BuildDaoManagers(XmlDocument document, Boolean useConfigFileWatcher) +163
[ConfigurationException:
- The error occurred while configure DaoSessionHandler.
- The error occurred in <property name="resource" value="SqlMap.config" xmlns="http://ibatis.apache.org/dataAccess" />.
- Check the IBatisNet.DataAccess.DaoSessionHandlers.SqlMapDaoSessionHandler.]
IBatisNet.DataAccess.Configuration.DomDaoManagerBuilder.BuildDaoManagers(XmlDocument document, Boolean useConfigFileWatcher) +208
IBatisNet.DataAccess.Configuration.DomDaoManagerBuilder.ConfigureAndWatch(String resource, ConfigureHandler configureDelegate) +113
SinoSoft.Health.Service.ServiceConfig.GetInstance() in D:\VSS\HealthWeb\Health\SinoSoft.Health.Service\ServiceConfig.cs:36
SinoSoft.Health.Service.CatalogService..ctor() in D:\VSS\HealthWeb\Health\SinoSoft.Health.Service\CatalogService.cs:32
SinoSoft.Health.Service.CatalogService..cctor() in D:\VSS\HealthWeb\Health\SinoSoft.Health.Service\CatalogService.cs:22
[TypeInitializationException: “SinoSoft.Health.Service.CatalogService”的类型初始值设定项引发异常。]
SinoSoft.Health.Service.CatalogService.GetInstance() in D:\VSS\HealthWeb\Health\SinoSoft.Health.Service\CatalogService.cs:44
SinoSoft.Health.Presentation.UserActions.CatalogAction..cctor() in D:\VSS\HealthWeb\Health\SinoSoft.Health.Presentation\UserActions\CatalogAction.cs:21
[TypeInitializationException: “SinoSoft.Health.Presentation.UserActions.CatalogAction”的类型初始值设定项引发异常。]
SinoSoft.Health.Presentation.UserActions.CatalogAction..ctor(HttpContext context) in D:\VSS\HealthWeb\Health\SinoSoft.Health.Presentation\UserActions\CatalogAction.cs:26
SinoSoft.Health.Web.WebForm1.DataBind1(String searchTxt) in D:\VSS\HealthWeb\Health\SinoSoft.Health.Web\WebForm1.aspx.cs:37
SinoSoft.Health.Web.WebForm1.Page_Load(Object sender, EventArgs e) in D:\VSS\HealthWeb\Health\SinoSoft.Health.Web\WebForm1.aspx.cs:26
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--------------------编程问答-------------------- 第33行代码呢? --------------------编程问答-------------------- builder.ConfigureAndWatch( "dao.config ", handler);
吓猜一个, 是不是handler is nothing
--------------------编程问答--------------------
代吗如下
public class ServiceConfig
{
static private object _synRoot = new Object();
static private ServiceConfig _instance;
private IDaoManager _daoManager = null;
/// <summary>
/// Remove public constructor. prevent instantiation.
/// </summary>
private ServiceConfig() { }
static public ServiceConfig GetInstance()
{
if (_instance == null)
{
lock (_synRoot)
{
if (_instance == null)
{
ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset);
DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
builder.ConfigureAndWatch("dao.config", handler);
_instance = new ServiceConfig();
// TODO:默认为sqlMapDao指定的Context, 要提供对多个Context的支持.
_instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao");
}
}
}
return _instance;
} --------------------编程问答--------------------
我在页面上是这样调用的,但是第一行久出错了
CatalogAction action2 = new CatalogAction(Context);
IList tt2 = (IList)action2.GetSearchList(searchTxt);
this.GridView1.DataSource = tt2;
this.GridView1.DataBind(); --------------------编程问答-------------------- builder.ConfigureAndWatch( "dao.config", handler);
再猜一个, 是不是"dao.config"没结尾空格
--------------------编程问答-------------------- 好像不是,我拿Npetshop弄就可以,自己的项目里面就不行 --------------------编程问答-------------------- 楼主呢,我今天遇到的问题和你的一样,
请问你当时是怎么解决了? --------------------编程问答-------------------- 知道了,麻烦- --------------------编程问答-------------------- 根据使用ibatis两年的经验
错误不在你的代码,你的代码应该是从另外的成熟的ibatis结构中拷贝出来的
错误应该是出现在你的配置文件中
包括maps文件和dao.config文件
[ConfigurationException:
- The error occurred while loading SqlMap.
- The error occurred in <sqlMap resource="Maps/Hb001Family.xml" xmlns="http://ibatis.apache.org/dataMapper" /> .]
IBatisNet.DataMapper.Configuration.DomSqlMapBuilder.Build(XmlDocument document, DataSource dataSource, Boolean useConfigFileWatcher, Boolean isCallFromDao) +287
IBatisNet.DataMapper.Configuration.DomSqlMapBuilder.Build(XmlDocument document, DataSource dataSource, Boolean useConfigFileWatcher, NameValueCollection properties) +45
IBatisNet.DataAccess.DaoSessionHandlers.SqlMapDaoSessionHandler.Configure(NameValueCollection properties, IDictionary resources) +528
[ConfigurationException: DaoManager could not configure SqlMapDaoSessionHandler.Cause:
- The error occurred while loading SqlMap.
- The error occurred in <sqlMap resource="Maps/Hb001Family.xml" xmlns="http://ibatis.apache.org/dataMapper" /> .]
IBatisNet.DataAccess.DaoSessionHandlers.SqlMapDaoSessionHandler.Configure(NameValueCollection properties, IDictionary resources) +610
IBatisNet.DataAccess.Configuration.DomDaoManagerBuilder.GetContexts(ConfigurationScope configurationScope) +1277
IBatisNet.DataAccess.Configuration.DomDaoManagerBuilder.BuildDaoManagers(XmlDocument document, Boolean useConfigFileWatcher) +163
仔细看这两段中加黑的部分
检查你的这两个文件
因为sqlmap加载失败,因此导致
ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset);
中的handler为null,当然就报 未将对象引用设置到对象的实例 错误了 --------------------编程问答-------------------- 一般是你的配置文件的问题,注重检查maps下的映射文件 --------------------编程问答-------------------- 我调试两天终于好了,看了我眼睛都花了!我可以肯定是源参考代码中的配置文件似乎格式有问题,还是里面可能有些很奇妙的空格等等!导致文档解析一直失败,建议楼主新建个项目,将配置一步步导入 到新的项目,不要一下子拷贝很多,你就会发现你的程序本来可以运行!还有一个问题是版本问题,建议去参考官方网站上的文档,相当有用!
补充:.NET技术 , ASP.NET