我有一个用户控件,它使用 CollectionEditor
的属性。我正在同一解决方案中使用另一个项目来测试控件。我的集合编辑器没有问题,除了在我重新编译组件 dll 后 IDE 在设计时给出错误。如果我关闭 IDE,然后重新打开解决方案,它就可以正常工作。如果我更改控件的代码并重新编译它,IDE 会给我同样的错误。我意识到如果我重新编译控件,IDE 不会为集合生成代码。但是如果我关闭并重新打开 IDE,它会生成代码。
错误信息:
Code generation for property 'AProperty' failed. Error was: '[A]MyComponent.AProperty cannot be cast to [B]MyComponent.AProperty. Type A originates from 'MyComponent; Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location '...\AppData\Local\Microsoft\VCSExpress\10.0\ProjectAssemblies\1f88w0l001\MyComponent.dll'. Type B originates from 'MyComponent; Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location '...\AppData\Local\Microsoft\VCSExpress\10.0\ProjectAssemblies\eb4apk_301\MyComponent.dll'.'
这是控件中的属性。
[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;
}
}
最佳答案
我在Time属性上遇到了这个问题,替换后解决了
SubTitleItem newSub = LearnItem.MainSub.GetSubByPosition(vlc.Time);
与
SubTitleItem newSub = LearnItem.MainSub.GetSubByPosition(GetPlayerPosition());
public long GetPlayerPosition() {
return vlc.Time;
}
--- 和 ---
if (LearnItem.PlayerPosition != 0) vlc.Time = LearnItem.PlayerPosition;
与
if (LearnItem.PlayerPosition != 0) SetPlayerPosition(LearnItem.PlayerPosition);
public void SetPlayerPosition(long Pos) {
vlc.Time = Pos;
}
也许这只是一个技巧,但它对我有用。
关于c# - CollectionEditor 和 "Code generation for property ' *** *' failed"错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7841476/