1

I'm working with .NET Compact Framework and just started to refactor some UI code. I'm defining a base user control to encapsulate common functionality, the project compiles OK but when I try to open a child user control in design mode I'm getting an error.

I made my class hierarchy taking into account this question. My classes are like this:

//on the data layer..
interface IDataObject {}
class Foo: IDataObject {}

//on the UI layer i have
class BaseDataUserControl<TDataObject> : UserControl 
where TDataObject : IDataObject {}

class FooUserControl : BaseDataUserControl<Foo> {}

This is the error I'm getting:

GenericArguments[0], 'Foo', on 'BaseDataUserControl`1[TDataObject]' violates the constraint of type 'TDataObject'

Can anyone point out to me why this does not work?

Community
  • 1
  • 1
RRoman
  • 741
  • 9
  • 19
  • 1
    From a language perspective, there is nothing wrong with your code. – Steven Aug 06 '10 at 18:05
  • yeah i know, maybe its something specific to the visual editor in VS =S – RRoman Aug 06 '10 at 18:09
  • Are you sure it's the same IDataObject everywhere? Place the cursor on each occurance, and hit F12 in Visual Studio to go to its definition. Do you end up in the same place every time? As @Steven said, the code as posted is fine, so alone it will not cause this problem. – Lasse V. Karlsen Aug 06 '10 at 18:11
  • @Lasse V. Karlsen i just made this exercise and yes its the same IDataObject =S – RRoman Aug 06 '10 at 18:19

1 Answers1

1

This has to be an ambiguity problem, the compiler sees a different definition of IDataObject when compiling FooUserControl. Which is easy to do, the System.Windows.Forms namespace already has an IDataObject interface.

Pick a different name or type the full namespace name.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Ok i renamed the class as you suggested and still did not work, so what i just did was to reboot my computer (horay for random ideas!) , after that i managed to get the visual editor to display my user control =), ...sad thing though =( – RRoman Aug 06 '10 at 19:59