Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't add usercontrol to form
Message
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01497539
Message ID:
01497700
Views:
40
>>>Hi All, I have a usercontrol in a class library that consists of nothing more than text boxes and labels. I have been using it on tab pages without a problem for a long time. Today I tried to drop it on a form from the toolbox and received a VS error: Failed to create component xxxx System.Runtime.InteropServices.COMException (0x80004005) Adding this project as a reference would cause a circular dependency etc... I've googled but haven't found anything of any help - any ideas ???
>>
>>I assume the UserControl is in a different assembly to the Form in which you want to use it?
>>If the assembly/project containing the UserControl contains a reference to the assembly/project containing the form then you can get this error since the IDE will attempt to add a reference in the opposite direction.....
>>If that's the case you will need to re-organise your assembly/class structure - maybe put the UserControl in a separate assembly (you can still use the same namespace)
>
>Hi Viv, you assumed correctly - I have all my UserControls in the same assembly, and , as they launch forms I have a reference to my forms assembly. Can't think of an easy way arround this one ! I'm all ears though ! Thanks for your time.

Strictly speaking this is an IDE problem - there's nothing in the .NET framework to prevent assemblies referencing each other (in fact I think there are a couple of examples of just that in the framework classes themselves).
So you can try to get round it by referencing the DLL rather than the project in one direction - but that is ugly, dangerous and messy.....
You can sometimes, as suggested above, get around this problem by factoring out classes into a separate assembly.
But if, as in your case, you want the UserControl to have access to specific properties or methods of its containing form you might be able to do this via interfaces:
Define an interface with the bits of the form that the UserControl should know about in a separate assembly referenced by the forms assembly and the UserControl assembly. Mark the form as implementing the Interface and give the user control a reference to the interface rather than the form.

Of course I've no idea whether the above strategy will work for you. I suppose I'd question whether if's good design for a UserControl to need such specific information about its runtime environment.....
Previous
Reply
Map
View

Click here to load this message in the networking platform