Tuesday, May 29, 2007

CAB error: A circular control reference has been made. A control cannot be owned by or parented to itself.

I've stumbled upon an interesting issue that nicely illustrates how the Composite UI Application Block requires you to change the way you think. It would seem a logical procedure to create your SmartPart control first (call WorkItem.Items.AddNew to do it) then add it to a workspace. But what if your control contains an embedded workspace by the same name? You'll get a circular reference exception ("A circular control reference has been made. A control cannot be owned by or parented to itself.") This is because CAB completely ignores the control hierarchy and has its own system of tracking components. When you add a SmartPart control to the WorkItem, all of its child SmartParts also get registered with the WorkItem, regardless of the fact that your SmartPart hasn't been added to the container control. So when you look for a workspace in the WorkItem, CAB will also detect workspaces inside the SmartPart.

Yeah, but what happens if you use the dependency injection instead of the AddNew method to create your SmartPart? You'd probably be stuck...

1 comment:

Lula said...

Interesting to know.