打开设计窗体报错:To prevent possible data loss before loading the designer
C# Code:
private void frmBase_Load(object sender, EventArgs e)
{
this.DoSetFont(SystemConfig.CurrentConfig.FontSize, true);
}
private void frmBase_Load(object sender, EventArgs e)
{
this.DoSetFont(SystemConfig.CurrentConfig.FontSize, true);
}
从这段代码可以看出问题吗? 编译后运行程序绝对没问题! 因为SystemConfig.CurrentConfig对象在运行程序第一时间已被实例化. 但是在设计环境下会报错:
To prevent possible data loss before loading the designer, the following errors must be resolved:
Object reference not set to an instance of an object.
为什么呢? 简直不可思议! VS开发工具在打开设计窗体时会检查或运行构造器, Load, Shown等事件内的代码! 当这些事件使用到未被实例化的对象或变量时, 错误呈现在你眼前. Delphi,VB等开发工具根本没这种情况.
无奈, 将代码改为:
C# Code:
private void frmBase_Load(object sender, EventArgs e)
{
if (SystemConfig.CurrentConfig!=null)
this.DoSetFont(SystemConfig.CurrentConfig.FontSize, true);
}
private void frmBase_Load(object sender, EventArgs e)
{
if (SystemConfig.CurrentConfig!=null)
this.DoSetFont(SystemConfig.CurrentConfig.FontSize, true);
}
或者SystemConfig.CurrentConfig对象在声明变量时实例化.

参考文档:
MySqlConnector.MySqlException:“Loading local data is disabled|C/S开发框架
Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the s
Win10安装TortoiseGit 2.14,The error code is 2503 解决方案
C# 对象克隆 TOut ObjectHelper.Clone |C/S开发框架
DataBinderTools.BoundComboBox方法,绑定ComboBox组件的下拉数据源-C/S开发框架
测试CSFramework.DB数据底层组件IDatabase.GetTop方法(Mssql/MySql)
C# Dev GridView表格的CustomUnboundColumnData事件异步加载图片类AsynDownImage
DevExpress GridView表格CustomUnboundColumnData事件异步加载图片
数字签名(Data Sign)+存取令牌(Access Token)双重安全请求WebApi接口
调用WebApi接口POST操作失败Unable to connect to the remote server
使用DataBinderTools工具类绑定下拉LookupEdit组件数据源
The server factory could not be located for the given input: Microsoft.Owin.Host.HttpListener
登录失败,请检查用户名和密码!CSFrameworkV5.DataAccess.DALFactory的类型初始值设定项引发异常
DbProviderFactories 加载Oracle.DataAccess.Client 失败
资料表工具类(DataTableTools)
How to changing the asp.net development server port?
MySqlConnector.MySqlException:“Loading local data is disabled|C/S开发框架
Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the s
Win10安装TortoiseGit 2.14,The error code is 2503 解决方案
C# 对象克隆 TOut ObjectHelper.Clone |C/S开发框架
DataBinderTools.BoundComboBox方法,绑定ComboBox组件的下拉数据源-C/S开发框架
测试CSFramework.DB数据底层组件IDatabase.GetTop方法(Mssql/MySql)
C# Dev GridView表格的CustomUnboundColumnData事件异步加载图片类AsynDownImage
DevExpress GridView表格CustomUnboundColumnData事件异步加载图片
数字签名(Data Sign)+存取令牌(Access Token)双重安全请求WebApi接口
调用WebApi接口POST操作失败Unable to connect to the remote server
使用DataBinderTools工具类绑定下拉LookupEdit组件数据源
The server factory could not be located for the given input: Microsoft.Owin.Host.HttpListener
登录失败,请检查用户名和密码!CSFrameworkV5.DataAccess.DALFactory的类型初始值设定项引发异常
DbProviderFactories 加载Oracle.DataAccess.Client 失败
资料表工具类(DataTableTools)
How to changing the asp.net development server port?
其它资料:
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
在线客服
