页面载入中......
首页 联系我 返回顶部
试着把Blog的数据缓存写成Windows Service,
web去调用该service中的数据
结果,出现的问题却是我始料未及的。

Blog是按标准的多层架构来编码的

Factory中反射出IDocument接口,代码如下:

public static LemongTree.Blog.IDAL.IDocument CreateIDocument()
        {
            string ClassName = path + ".DocumentSQLDAL";
       
            try
            {
                WebLog.WriteLog("Debug:" + ClassName);
                IDocument doc = (IDocument)Assembly.Load(path).CreateInstance(ClassName);
                WebLog.WriteLog("IDocument创建成功:");
                return doc;
            }
            catch (Exception ex)
            {
                WebLog.WriteLog("DataAccess Error:" + ex.ToString());
                return null;
            }
        }
这段代码直接在iis中运行一点问题都没有,但做成windows服务后,捕获的异常为:

2007-8-7 22:17:32:Debug:LemongTree.Blog.DAL.SQLServer.DocumentSQLDAL  //factory层红色部分
===================================================
2007-8-7 22:17:32:DataAccess Error:System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 BlogConfig..ctor()
   在 BlogConfig.get_Instance()
   在 LemongTree.Blog.DAL.SQLServer.DocumentSQLDAL..ctor()
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   在 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   在 System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   在 System.Activator.CreateInstance(Type type, Boolean nonPublic)
   在 System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   在 System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   在 System.Reflection.Assembly.CreateInstance(String typeName)
   在 LemongTree.Blog.Factory.DataAccess.CreateIDocument()

由上面的异常可以看出,运行到IDocument doc = (IDocument)Assembly.Load(path).CreateInstance(ClassName);时捕获到异常,
也就是说在反射时失败了,难道不能在windows服务器运用?

是我的疏忽,代码是正确的,也可以反射,仔细分析了一下,发现是我配置文件的问题 ^_^

Write a comment:



(将显示你的Gravatar图标)  



[b][/b] - [i][/i] - [u][/u]- [quote][/quote]

:-/ ^_^ :d :o :kiss: :) :p :se: [yeah] :( :love: :han: :up: :cry: :zzz: o_o

暂时停止交换链接.

评论提交有问题?