create WorkItem; remove it; create again => except

Topics: CAB & Smart Client Software Factory
Jul 20, 2005 at 7:48 AM
originally posted by: Artem

Hi,

I have a work item that does not live long. When I need to perform certain action I create it, run and then dispose.
It works fine first time, but when I am trying to do it again it fails with the following exception:

"Service Microsoft.ApplicationBlocks.CompositeUI.IWorkItemActivationService, required for component test.MyWorkItem is not available in the current container."

I will appreciate anyone pointing were I am doing a wrong thing or is it actually a problem in current version of CAB.
BTW I am using Tech Preview 1.

Code to reproduce:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Practices.ComponentModel;
using Microsoft.ApplicationBlocks.CompositeUI;

namespace test
{
class MyWorkItem : WorkItem
{
public MyWorkItem()
{
}

public void Run()
{
Activate(); //fine first time; exception second.
MessageBox.Show("working...");
}
}

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
STAThread
static void Main()
{
ApplicationHost host = new ApplicationHostFactory().CreateHost();

host.Initialize();

MyWorkItem wki = host.DefaultWorkItem.Create<MyWorkItem>("wki");
wki.Run();
host.DefaultWorkItem.Remove(wki);
wki.Dispose();

wki = host.DefaultWorkItem.Create<MyWorkItem>("wki");
wki.Run(); //exception
host.DefaultWorkItem.Remove(wki);
wki.Dispose();

Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
}
Jul 21, 2005 at 7:42 AM
originally posted by: Artem

Never mind. I figured it out.

If I call

wki.Terminate();

instead of

host.DefaultWorkItem.Remove(wki);
wki.Dispose();

it works fine.
Aug 4, 2005 at 5:10 PM
originally posted by: YuriAstrakhan

The second lab has the same problem. Both
labs\cs\02 WorkItems\exercises\ex03\end\
and
labs\cs\02 WorkItems\exercises\ex03\end\
cause this exception after clicking accept, double clicking Brad Smith, closing custome form, and double clicking again.

Please note that the folder "Microsoft patterns & practices" was renamed to avoid the "&" bug in vs form designer.

System.InvalidOperationException was unhandled
Message="Smart part has not been sited in a valid container or work item."
Source="Microsoft.ApplicationBlocks.CompositeUI.WinForms"
StackTrace:
at Microsoft.ApplicationBlocks.CompositeUI.WinForms.WorkspaceUtilities.ThrowIfNotSited(Control smartPart) in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\Src\CS\CompositeUI.WinForms\WorkspaceUtilities.cs:line 94
at Microsoft.ApplicationBlocks.CompositeUI.WinForms.WorkspaceUtilities.GetSmartPartControl(Object smartPart) in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\Src\CS\CompositeUI.WinForms\WorkspaceUtilities.cs:line 49
at Microsoft.ApplicationBlocks.CompositeUI.WinForms.MdiWorkspace.Show(Object smartPart, ISmartPartInfo smartPartInfo) in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\Src\CS\CompositeUI.WinForms\MdiWorkspace.cs:line 72
at Microsoft.ApplicationBlocks.CompositeUI.WinForms.WindowWorkspace.Show(Object smartPart) in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\Src\CS\CompositeUI.WinForms\WindowWorkspace.cs:line 98
at BankTellerModule.CustomerWorkItem.OnStatusChanged() in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\labs\cs\02 WorkItems\exercises\ex03\end\BankTellerModule\WorkItems\Customer\customerworkitem.cs:line 86
at Microsoft.ApplicationBlocks.CompositeUI.WorkItem.ChangeStatus(WorkItemStatus newStatus) in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\Src\CS\CompositeUI\WorkItem.cs:line 358
at Microsoft.ApplicationBlocks.CompositeUI.WorkItem.Activate() in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\Src\CS\CompositeUI\WorkItem.cs:line 203
at BankTellerModule.BankTellerWorkItem.WorkWithCustomer(Customer customer) in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\labs\cs\02 WorkItems\exercises\ex03\end\BankTellerModule\WorkItems\BankTeller\BankTellerWorkItem.cs:line 68
at BankTellerModule.CustomerQueueController.WorkWithCustomer(Customer customer) in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\labs\cs\02 WorkItems\exercises\ex03\end\BankTellerModule\WorkItems\BankTeller\CustomerQueueController.cs:line 41
at BankTellerModule.CustomerQueueView.listCustomers_SelectedIndexChanged(Object sender, EventArgs e) in c:\Program Files\Microsoft patterns and practices\Composite UI Application Block Tech Preview 1\labs\cs\02 WorkItems\exercises\ex03\end\BankTellerModule\WorkItems\BankTeller\CustomerQueueView.cs:line 57
at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)
...
Aug 31, 2005 at 4:31 AM
originally posted by: andersmh

I am also getting this error when I try to terminate my workitems.

In my controlling workitem i terminate 2 "sub" workitems,
workitem1.Terminate();
workitem2.Terminate();

and i get the error that the smartparts are not sited

was there a solution to this that i missed ? I appreciate any replies.

Best regards,
Anders H