本地测试,远程部署都完全没问题。但是运行一段时间后WCF会出现错误,提示未将对象引用错误,即对象是空的,3到5天出一次异常,
代码结构:
后台:
   public class Srv_Bas : Srv.Srv_Master, ISrv_Bas
    {
        BL_Base bl_BaseInfo;
        public Srv_Bas()
        {
            bl_BaseInfo = new BL_Base(subsystemModuleData.Bas.DBid);
            bl_BaseInfo.subsystemModuleData = subsystemModuleData;
            masterbl = bl_BaseInfo;
        }
    }    public class Srv_Master
    {
        public DataTable getDataTable(string strSql)
        {
            if (masterbl == null)
                throw new Exception("masterbl is null");
            if (String.IsNullOrWhiteSpace(strSql))
                throw new Exception("strSql IsNullOrWhiteSpace");
            return masterbl.getDataTable(strSql);
        }
   }前台:
                Type type = srvClient.GetType();
                try
                {
                    return (DataTable)type.InvokeMember("getDataTable", System.Reflection.BindingFlags.Default
                        | System.Reflection.BindingFlags.InvokeMethod, null, srvClient, new object[] { strSql });
                }
                catch (Exception _e)
                {
                    string InterExceptionMsg="";
                    if (_e.InnerException !=null)
                        InterExceptionMsg= _e.InnerException.Message;
                    throw new Exception("方法getDataTable(" + strSql + ")出错了。\r" + _e.Message + "\rInnerException:" + InterExceptionMsg);
                }

解决方案 »

  1.   

    你导出throw异常都没事,难道就一个null异常就崩溃了?前台出错还是后台出错你自己先要确定,总不能直接把代码一贴就不管了,别人可没有环境进行调试,但看那几行代码根本没错误,更何况你也不可能给全代码。
      

  2.   

    非常感谢1楼的回复
    1.首先要声明的是正常运行没有问题,过一段时间后发生错误,重新发布WCF又会好,周而复始
    2.从出错的信息来看是后台出的错误,很明显InnerException返回的错误,是前台参数没有传送的后台引起的如strSql没有传到后台。因此考虑到是不是长期反射调用WCF后台参数无法传递引起的从另一个帖子看是IIS的问题,但这似乎跟IIS没有直接的关系,因为反射是前台反射的,已加batch="false",效果未知如下是参考链接
    http://topic.csdn.net/u/20090524/21/108ec37f-2eb1-4096-8d36-e961cb8cea52.html
      

  3.   

    既然你用的是WCF,那么为啥不用接口调用其服务,还用反射?
      

  4.   

    这种东西不是靠翻来覆去地“跟代码相面”而找出问题来的。善于测试驱动开发,你每天都能随机挑选数据进行成千上万次、打乱次序、甚至多线程并发的回归测试,自然可以迅速发现能够重现其bug的数据来。手工,或者让别人也是手工操作,去跟代码相面,我是挑不出什么问题来。
      

  5.   

    这种bug就自己再去花点时间从头开始吧。
      

  6.   

    回复3楼,
    这是因为有功能类似的几个类,都要用到getDataTable,因此只有继承基类就不要写几个,所以用到了反射
    主要是看看有没有哪位大侠有这方面的经验可以借鉴
      

  7.   

    batch="false"解决的是"未能加载文件或程序集"这样的错误。
    你的问题是"未将对象引用错误",我觉得八成还是你代码的问题。这种不定期,不是100%重现的问题不是很容易解决。
    我的解决办法是,
    1. 测试,写个简单测试端,开线程模拟并发,循环,做大量测试,看是否能够重现。
    2. 你有CallStack,知道那个函数出的问题,在函数开始将所有参数写log,问题出现中从log取得数据,对函数进行测试。
      

  8.   

    看Call Stack是在你的函数中出错的吗?
      

  9.   

    或者说使用WCF有没有反射调用的案例
      

  10.   

    你好我也是猜测,如果能正常运行的,现在这个wcf 调用人是不是量比较大最大链接数配置了么?
    <serviceBehaviors>
    <behavior name="NetStars.Soft_SecurityPlatform.WcfService.BBsService">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceThrottling maxConcurrentCalls="10000" maxConcurrentInstances="2147483647" maxConcurrentSessions="10000" />
    </behavior>
    其次就是,前端验证做好了么?sql null 或者 sql 格式有误
      

  11.   

    量很大,maxConcurrentInstances="10000"设置成10000,跟楼上的有差异
      

  12.   

    详细错误:
    WebHost failed to process a request.
     Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/3323268
     Exception: System.ServiceModel.ServiceActivationException: The service '/UnifiedInfos/srvMES/MesSrv.Srv_Mes.svc' cannot be activated due to an exception during compilation.  The exception message is: Object reference not set to an instance of an object.. ---> System.NullReferenceException: Object reference not set to an instance of an object.
       at System.Web.Compilation.DiskBuildResultCache.CacheBuildResult(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart)
       at System.Web.Compilation.BuildManager.CacheBuildResultInternal(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart)
       at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
       at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
       at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
       at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate)
       at System.Web.Compilation.BuildManager.GetCompiledCustomString(String virtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.GetCompiledCustomString(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
       --- End of inner exception stack trace ---
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
     Process Name: w3wp
     Process ID: 18536
      

  13.   

    期待高手,是不是。NET 4。0有补丁可以打?参考文档
    http://cheny.sh.blog.163.com/blog/static/49675535201251423549294/
    http://stackoverflow.com/questions/5002386/problems-with-notfound-errors-and-compilation-failures
      

  14.   

    问题已找到,在构造函数中有一个static不安全引起的问题