未在用户控件中初始化?

发布于 2024-10-11 16:57:06 字数 1188 浏览 3 评论 0原文

关于为什么 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与往事干杯 2024-10-18 16:57:07

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文