开发者

Not initialized in user control?

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 u开发者_运维技巧ser 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)  


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜