未在用户控件中初始化?
关于为什么 AR 在用户控件内部使用时未正确初始化的任何想法?我的初始化正在正确执行,因为我的父表单能够成功查询。但是,当我尝试在用户控件中查询时,我收到警告 1 使用了 ActiveRecord 类(Binder),但框架似乎未正确初始化。您忘记了 ActiveRecordStarter.Initialize() 吗? 0 0 。这阻止我将用户控件拖到表单上。如果有帮助,我会在 Program.Main() 中初始化 AR。
这是堆栈跟踪:
at Castle.ActiveRecord.ActiveRecordBase.EnsureInitialized(Type type)
at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType, DetachedCriteria detachedCriteria, Order[] orders)
at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType)
at Castle.ActiveRecord.ActiveRecordBase`1.FindAll()
at TxLocates.BinderTabReferenceControl.BinderTabReferenceControl_Load(Object sender, EventArgs e) in C:\dev\TxLocates\src\TxLocates\BinderTabReferenceControl.cs:line 56
at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
at System.Windows.Forms.UserControl.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at System.Windows.Forms.Form.ControlCollection.Add(Control value)
at System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add(Control c)
Any ideas as to why AR isn't being properly initialized when being used inside a user control? My initialization is properly being executed AFAIK because my parent form is successfully able to query. However, when I try querying within my user controls I get Warning 1 An ActiveRecord class (Binder) was used but the framework seems not properly initialized. Did you forget about ActiveRecordStarter.Initialize() ? 0 0
. Which stops me from dragging my user control onto the form. If it helps, I initialize AR in Program.Main().
Here is the stacktrace:
at Castle.ActiveRecord.ActiveRecordBase.EnsureInitialized(Type type)
at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType, DetachedCriteria detachedCriteria, Order[] orders)
at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType)
at Castle.ActiveRecord.ActiveRecordBase`1.FindAll()
at TxLocates.BinderTabReferenceControl.BinderTabReferenceControl_Load(Object sender, EventArgs e) in C:\dev\TxLocates\src\TxLocates\BinderTabReferenceControl.cs:line 56
at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
at System.Windows.Forms.UserControl.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at System.Windows.Forms.Form.ControlCollection.Add(Control value)
at System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add(Control c)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Visual Studio 设计器为用户控件执行 OnLoad,但不运行 Program.Main()。因此 ActiveRecord 不会在设计器的上下文中初始化。
解决方法:使用 DesignMode 属性 检测设计模式以避免执行 ActiveRecord 相关代码,或尝试从不同的事件调用 ActiveRecord。
The Visual Studio designer executes OnLoad for your user control, but doesn't run Program.Main(). Therefore ActiveRecord isn't initialized in the context of the designer.
Workarounds: use the DesignMode property to detect design mode to avoid executing ActiveRecord-related code, or try calling ActiveRecord from a different event.