4

I have a class declared as:


public class Foo<T> : Panel where T : Control, IFooNode , new()
{
 ...
}

I added it by hand to test it, but I will eventually need something that can be displayed in the Forms designer. The Forms designer doesn't like this, it says:

Could not find type 'FooTestNameSpace.Foo'.
Please make sure that the assembly that
contains this type is referenced.
If this type is a part of your development project, make
sure that the project has been successfully built. 

Interestingly, I ALSO get a warning that is similar, but includes the generic type I used in my declaration of the variable. Warning is:

Could not find type 'FooTestNameSpace.Foo<FooTestNameSpace.FooNodeType>'.
Please make sure that the assembly that contains this type is referenced.
If this type is a part of your development project,
make sure that the project has been successfully built.

The declaration in my simple Form1 class is:

private FooTestNameSpace.Foo myFoo;

(FooNodeType is really just a subclass of Label that has one auxiliary property not yet being used; it does implement IFooNode).

So my question... With this type of set up, how can I get Foo to be displayed on the Forms designer, or at least get it to acknowledge that Foo is legit? Is there any Designer attribute that can handle this? I don't really care if my Foo control appears as an empty box, as long as it appears at all!

asked Oct 20, 2009 at 2:54
2
  • 2
    The designer is nice for simple drag & drop things. For more intricate class signatures, you may be expecting too much. Commented Oct 20, 2009 at 3:00
  • It might be more helpful if you also explained exactly what you're trying to accomplish with that view class and perhaps show some more code. It's entirely possible that you're just missing a using statement but it's impossible to tell from your snippet. Commented Oct 20, 2009 at 3:14

2 Answers 2

7

Ok, I think I have a solution:


class ConcreteFooCtl : FooCtl<FooNodeType>
{
}
class FooCtl<T> : Panel where T : Control, IFooNode , new()
{
}

The problem seems to be that the Forms designer can't handle any generic control. The forms designer can't handle FooCtl, but has no problems with ConcreteFooCtl. Not an ideal solution, but I think it's at least workable. Maybe the next version of VS will prompt the user to specify a generic type when adding a generic control to a form... ;)

answered Oct 20, 2009 at 3:13

1 Comment

This is the right solution to this problem. I've had the same problem since a year ago and haven't found any other solution yet.
1

Instead of making Foo a generic, you might be better of making it non generic, and having it contain a generic class that does what you need. You can then delegate all your processing from the form to the class.

answered Oct 20, 2009 at 3:13

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.