我有一個用戶控件,使用屬性CollectionEditor
。我在同一解決方案中使用另一個項目來測試控件。我的集合編輯器在沒有問題的情況下工作,除了IDE在重新編譯組件dll之後在設計時提供了錯誤。如果我關閉了IDE,那麼重新打開解決方案,它就可以毫無問題地工作。如果我更改了控件的代碼並重新編譯它,IDE給了我同樣的錯誤。我意識到如果我重新編譯控件,IDE不會爲集合生成代碼。但是,如果我關閉並重新打開IDE,它會生成代碼。CollectionEditor和「代碼生成屬性」****'失敗「錯誤消息
錯誤消息:
代碼生成屬性「AProperty失敗。錯誤是:'[A] MyComponent.AProperty不能轉換爲[B] MyComponent.AProperty。類型A來源於'MyComponent;在位置'... \ AppData \ Local \ Microsoft \ VCSExpress \ 10.0 \ ProjectAssemblies \ 1f88w0l001 \ MyComponent.dll'中的上下文「LoadNeither」中的版本= 1.0.0.0,Culture = neutral,PublicKeyToken = null。類型B來自'MyComponent;在位置'... \ AppData \ Local \ Microsoft \ VCSExpress \ 10.0 \ ProjectAssemblies \ eb4apk_301 \ MyComponent.dll'的上下文'LoadNeither'中的版本= 1.0.0.0,Culture = neutral,PublicKeyToken = null'。
這是控件中的屬性。
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ACollectionEditor), typeof(UITypeEditor))]
public ACollection AProperty { get { return prop; } }
而下面是CollectionEditor
的代碼:
public class ACollectionEditor : CollectionEditor
{
protected override object CreateInstance(Type itemType)
{
nameCounter++;
//var newObj = Activator.CreateInstance(itemType, new object[] { "AProperty" + nameCounter.ToString(), parent});
var newObj = new AProperty("AProperty" + nameCounter.ToString());
return newObj;
}
}