CollectionEditor and "Code generation for property '****' failed" Error Message

880 Views Asked by At

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

There are 1 best solutions below

0
On

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.