我在这里看到过这样的问题,但我没有找到答案。
我有两个项目:
- WinForms 库
- BaseUserComponent(继承自System.ComponentModel.Component的抽象类
- MyControl(具有名为Component的BaseUserComponent类型的属性)
- WinForms 应用程序
- UserComponent(BaseUserComponent的实现)
- 表单(包含UserComponent和MyControl)
问题是当设计师试图将MyControl的Component属性分配给UserComponent的实例时。当我第一次打开设计器时,一切正常,但在表单设计器发生任何更改后都会显示错误。但是继承自,所以它应该可以正常工作。'Object of type 'UserComponent' cannot be converted to type 'BaseUserComponent'
UserComponent
BaseUserComponent
例外:
at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkPropertyDescriptor.SetValue(Object component, Object value)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertyAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement, CodePropertyReferenceExpression propertyReferenceEx, Boolean reportError)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
我尝试重建整个解决方案,多次进行项目,但没有任何效果。