CollectionEditor 和“属性代码生成****”;失败”错误信息

发布于 2024-12-11 05:44:26 字数 1425 浏览 0 评论 0原文

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

错误信息:

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

这是控件中的属性。

    [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;
    }
}

I have a user control that uses a property with CollectionEditor. And I'm using another project in the same solution to test the control. My collection editor works without a problem, except the IDE gives the error in design-time after I recompiled the component dll. If I close the IDE, than reopen the solution, it works without a problem. If I change the code of the control and recompile it, IDE gives me the same error. I realised that IDE doesn't generate code for the collection if I recompile the control. But if I close and reopen the IDE, it generates the code.

Error Message:

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'.'

Here is the property in the control.

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Editor(typeof(ACollectionEditor), typeof(UITypeEditor))]
    public ACollection AProperty { get { return prop; } }

And the following is the CollectionEditor's codes:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱影子 2024-12-18 05:44:26

解决了它

SubTitleItem newSub = LearnItem.MainSub.GetSubByPosition(vlc.Time);

我在使用属性 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;
}

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

I had this problem with propety Time and had solved it after replace

SubTitleItem newSub = LearnItem.MainSub.GetSubByPosition(vlc.Time);

with

SubTitleItem newSub = LearnItem.MainSub.GetSubByPosition(GetPlayerPosition());

public long GetPlayerPosition() {
    return vlc.Time;
}

--- and ---

if (LearnItem.PlayerPosition != 0) vlc.Time = LearnItem.PlayerPosition;

with

if (LearnItem.PlayerPosition != 0) SetPlayerPosition(LearnItem.PlayerPosition);

public void SetPlayerPosition(long Pos) {
    vlc.Time = Pos;
}

Perhaps it's only a trick, but it's work for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文