Error: An object with this ID already exists

Topics: CAB & Smart Client Software Factory
Jun 26, 2006 at 3:00 AM
originally posted by: MyKey0815

I have create two SmartParts (User Controls). In my shell I have following code to remove the SmartParts when they didn´t need anymore

Public Sub ClearSmartParts()

With deckWsDetails
Do Until .SmartParts.Count = 0
.Close(deckWsDetails.SmartParts.Item(0))
Loop

End With


End Sub

They work good!

Now I will combine the 2 SmartParts to one. I create a new User Control. Add the TabWorkspace and put the 2 SmartParts on 2 pages of the TabWorkspace. Then it is possible to show the combined SmartPart. When I will close the SmartPart I press the button they run 'ClearSmartPart' - The smartPart dind´t shown anymore.

But when I will show the combind Smartpart again, I have the Error "An object with this ID already exists" an the name of the TabWorkspace.

What can I do? What is the better way? Can anyone help me?

CU
Michael Kolowicz
Sep 19, 2006 at 10:56 AM
originally posted by: Shiraz

We are getting the same error.

In our case we have a SmartPart that contains other SmartParts. This works fine as long as we only open one copy of the main SmartPart open.

However, when we open 2 copies, we get the same error as you "An object with this ID already exists".

We suspect that the SmartParts are registering themselves with the CAB event broker, using the name of the control.
Sep 26, 2006 at 3:54 AM
originally posted by: ForumUserRCC

I have a similar problem and posted over a month ago about it but never heard anything. My suspicion is similar to Shiraz comment.
I ended up having to code to remove each Smart Part.
So i had a View that contained multiple user controls (each of them a Smart Part). when it comes time to close and remove the view, I have to remove it PLUS remove the Smart Parts that are used in the view.
I would have expected that since the View contains the Smart Parts that by removing it, that any parts or controls it contained would get removed. Seems like since their "container" is gone, they should be gone too. But they stick around unless you remove them too.
By doing that, I got around the "already exists" problem.
Jan 5, 2007 at 12:36 AM
originally posted by: RobertEwen

hi,

the normal behaviour of a workspace of closing a containing smartpart, is to Hide it, not to dispose it.

So just try to make the following:

workspace.Show(workItem.SmartParts.Get(viewID) ?? _workItem.SmartParts.AddNew<View>(viewID));

-> Look inside the corresponding workitem to see if there is already an instance of the view. otherwise create the view ...


Kind regards
Robert