日期:2014-05-19  浏览次数:20776 次

我的程序一运行就提示:Dispose错误.
程序一运行   ,我跟踪它看到
不运行构造函数却运行到了

            protected   override   void   Dispose(bool   disposing)
                {
                        if   (disposing)
                        {
                                if   (components   !=   null)
                                {
                                        components.Dispose();
                                }
                        }
                    base.Dispose(disposing);
                }
而且提示:未将对象引用设置到对象的实例
为什么?

------解决方案--------------------
可是如果我不通过反射Form form = this.ActivateFormInstance(null, typeName);而是通过TForm form1 =new TForm()
form1.show()
就不抛出异常啊.
__________________________________________________________________

在从反射生成时候, 语句 Assembly.GetCallingAssembly().GetManifestResourceStream( "El.images.huaif.jpg ") 中的 Assembly 可能不是你原来那个定义了Form的确 "Assembly ",所以在它里边也找不到 "El.images.huaif.jpg " 文件, 这样一来(Bitmap)Image.FromStream(Assembly.GetCallingAssembly().GetManifestResourceStream( "El.images.huaif.jpg "))就会返回null,也就是 "未将对象引用设置到对象的实例 " 异常.