2011-01-12 57 views
0

有關爲什麼AR在用戶控件內部使用時未被正確初始化的任何想法?我的初始化正在正確執行AFAIK,因爲我的父表單能夠成功查詢。但是,當我嘗試在用戶控件中查詢時,我得到Warning 1 An ActiveRecord class (Binder) was used but the framework seems not properly initialized. Did you forget about 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) 

回答

2

Visual Studio設計執行的OnLoad您的用戶控制,但不運行Program.Main()。因此,ActiveRecord在設計器的上下文中不會被初始化。

解決方法:使用DesignMode property檢測設計模式以避免執行與ActiveRecord相關的代碼,或嘗試從其他事件調用ActiveRecord。

+0

完全有意義。謝謝,Mauricio。 – Mike 2011-01-16 18:28:26