c# - CollectionEditor 和 "Code generation for property ' *** *' failed"错误信息

标签 c# .net user-controls custom-controls collectioneditor

我有一个用户控件,它使用 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/

相关文章:

c# - Linq2SQL:事务涵盖了SubmitChanges?

c# - 简单高级的布局

.net - JavaScriptSerializer UTC DateTime 问题

c# - 如何防止 usercontrol 表单处理 c# 中的键盘输入(箭头键)

c# - ASP.NET Core 5 API 在 Azure Web App 磁盘空间上写入文件

.net - 为EF提供即时的自定义数据库提供程序

.net - Microsoft.VisualBasic.FileIO.TextFieldParser 将 ± Ascii 241 更改为 ? ASCII 63

c# - 我可以在 1 个应用程序中拥有同一个 UserControl 的多个实例吗?

c# - 同一控件中的 WPF 失去焦点问题

C# 从包含数字和单词的字符串中获取数字序列?