CollectionEditor 和“属性代码生成****”;失败”错误信息
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了它
我在使用属性 Time 时遇到了这个问题,并在替换为
--- 和 ---
后
。 也许这只是一个技巧,但它对我有用。
I had this problem with propety Time and had solved it after replace
with
--- and ---
with
Perhaps it's only a trick, but it's work for me.