【问题标题】:CollectionEditor and "Code generation for property '****' failed" Error MessageCollectionEditor 和“属性 '****' 的代码生成失败”错误消息
【发布时间】:2011-12-12 02:12:15
【问题描述】:

我有一个使用CollectionEditor 属性的用户控件。我在同一个解决方案中使用另一个项目来测试控件。我的集合编辑器可以正常工作,除了 IDE 在我重新编译组件 dll 后在设计时给出错误。如果我关闭 IDE,而不是重新打开解决方案,它可以正常工作。如果我更改控件的代码并重新编译它,IDE 会给我同样的错误。我意识到如果我重新编译控件,IDE 不会为集合生成代码。但是如果我关闭并重新打开 IDE,它会生成代码。

错误信息:

属性“AProperty”的代码生成失败。错误是:'[A]MyComponent.AProperty 无法转换为 [B]MyComponent.AProperty。 A 型源自 'MyComponent; Version=1.0.0.0,Culture=neutral,PublicKeyToken=null',位于位置 '...\AppData\Local\Microsoft\VCSExpress\10.0\ProjectAssemblies\1f88w0l001\MyComponent.dll' 的上下文 'LoadNeither' 中。 B 型源自 'MyComponent; Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 在上下文 'LoadNeither' 的位置'...\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;
    }
}

【问题讨论】:

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


    【解决方案1】:

    我在 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;
    }
    

    也许这只是一个技巧,但它对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      • 1970-01-01
      相关资源
      最近更新 更多