Re-adding a removed smart part causing key already exists

Jan 10, 2008 at 4:25 AM
Hi guys,

I've run into a strange proplem where if I re-add a removed smart part to a workspace, I get the message saying that the key already exists even though the key does not exist in the workspace or workitem collections. The code is shown below:

If Not WorkItem.Workspaces(WorkspaceNames.CenterWorkspace).SmartParts.Contains(mView) Then
If WorkItem.Workspaces(WorkspaceNames.CenterWorkspace).ActiveSmartPart IsNot Nothing Then
End If
ShowFormInWorkspace(mView, "ProfileView", WorkspaceNames.CenterWorkspace)
End If

This code is used in every module we've created except for this one. If we open this smart part, switch to another, then re-open it, the error comes back saying "An item with the given key is already present in the dictionary." with the following stack trace:

" at Microsoft.Practices.ObjectBuilder.WeakRefDictionary`2.Add(TKey key, TValue value)
at Microsoft.Practices.ObjectBuilder.Locator.Add(Object key, Object value)
at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.BuildRepeatedItem(Type typeToBuild, String idToBuild, Object item)
at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.Build(Type typeToBuild, String idToBuild, Object item)
at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.Add(TItem item, String id)
at SDM.Mobile.PocketPhrase.AdminTool.Infrastructure.Interface.WorkItemController.ShowFormInWorkspace(Object& instance, String viewId, String workspaceName) in WorkItemController.vb:line 48

The weird thing is that if the value of mView is changed to something else, it works and it keeps working regardless of what you do. Anyone got any ideas here?