error: one or more exceptions occurred while firing topic,changetreevalue, - very urgent

Topics: CAB & Smart Client Software Factory
Aug 27, 2008 at 9:52 PM
Hi All,
     I am new to scsf can you please help me with my issue:

I have a tree view coming up in the shell which has all company names as childs on the left hand side workspace .I have a context menu strip called add company on treview root.Once i click add company i have  a add company view coming in the right workspace but in order to load the view i am loading a view on the right workspace (wich comes with company tab) then on that i have a tab workspace on that view and add company view is coming on tab workspace .Now i am doing some actions on ad company view and hitting the save button.Then i am firing an event on clicking the button.Now once i am done with this i am refreshing the treeview with newly added company.For this  i am subscribing the event in the other module which has view that contains treeviewcontrol in module controller.cs .Then i am getting an exception    : ONE OR MORE EXCEPTIONS OCCURRED WHILE FIRING TOPIC 'ChangeTreeValue'.

The code in addcompanypresenter.cs is as follows


[

EventPublication(EventTopicNames.ChangeTreeValue, PublicationScope.Global)]

 

 

public event EventHandler<EventArgs> ChangeTreeValue;


 

 

public void AddCompany(int CompanyID, string City, string State, string CompanyName)

 

{

ChangeTreeValue(

this, new EventArgs());

 

OnCloseView();

}


In the Module where i have the treeview inthat modulecontroller.cs i have the code as follows .It has a view called navigation view and i am calling the method on that view.


 

[EventSubscription(BR_CMS_UI.Infrastructure.Interface.Constants.EventTopicNames.ChangeTreeValue, Thread = ThreadOption.UserInterface)]

 

 

 

 

public void ChangeTreeValue(object sender, EventArgs e)

 

{

 

NavigationView vw = new NavigationView();

 

vw.ChangeTreeValue();

}

 


Please can anyone look into this and tell me where i am getting the error.I saw one post somewhat similar to this but i didnt get that so please explain me briefly. 

Thank You,
Bindu.

 

 

 

 

Aug 28, 2008 at 2:34 PM
Bindu,

the exception you get is not the "real" one. Look at the inner exception and at the call stack. That will help you to find the actual error.

Regards, Gerald
Developer
Aug 28, 2008 at 3:41 PM

Hi

 

For what I see in your code snippets, there is no problem in the way that you are using the Event Broker.

This kind of exception is usually thrown when the event handler throws an exception. You should check if the ChangeTreeValue method is throwing an exception. You can do this by wrapping the contents of the method in a try/catch statement like the following:

 

[EventSubscription(EventTopicNames.ChangeTreeValue, Thread = ThreadOption.UserInterface)]

public void ChangeTreeValue(object sender, EventArgs e)

{

    try

    {

        NavigationView vw = new NavigationView();

        vw.ChangeTreeValue();

    }

    catch (Exception exception)

    {

        MessageBox.Show(exception.Message);

    }

}

 

Or you can review the content of the EventTopicException exception by clicking in the View Detail… button of the exception dialog, and check the content of the Exceptions property. There you will find the root exception that causes the problem.

 

You are creating a new NavigationView view every time you raise the ChangeTreeValue event and you are not using the WorkItem to create it. Try to replace this line:

 

                NavigationView vw = new NavigationView();

 

With the following one:

 

                NavigationView vw = ShowViewInWorkspace<NavigationView>(WorkspaceNames.LeftWorkspace);

 

Note: Perhaps a better approach could be putting the event handler of the ChangeTreeValue event in the presenter of the NavigationView view to update its content instead of creating a new one every time.

 

Please, let me know if it helps.

 

Mariano Converti

http://blogs.southworks.net/mconverti

Aug 28, 2008 at 10:20 PM
Hi Gerald and Mariano,

Thank You for your reply .
Now i have moved my event subscription to Navigationview presenter included try and catch blocks as following:

[

EventSubscription(BR_CMS_UI.Infrastructure.Interface.Constants.EventTopicNames.ChangeTreeValue, Thread = ThreadOption.UserInterface)]

 

 

public void ChangeTreeValue(object sender, EventArgs e)

 

{

 

try

 

{

 

NavigationView vw = new NavigationView();

 

vw.ChangeTreeValue();

 

}

 

catch (Exception ep)

 

{

 

MessageBox.Show(ep.Message);

 

}

}

 also tried writing as below

[

EventSubscription(BR_CMS_UI.Infrastructure.Interface.Constants.EventTopicNames.ChangeTreeValue, Thread = ThreadOption.UserInterface)]

 

 

public void ChangeTreeValue(object sender, EventArgs e)

 

{

 

try

 

{

 

//NavigationView vw = new NavigationView();

 

//vw.ChangeTreeValue();

 

View.ChangeTreeValue();
}

 

catch (Exception ep)

 

{

 

MessageBox.Show(ep.Message);

 

}

}





Now i am getting a exception as object reference not set to instance of an object.
Can you please look into it.

Thanks in advance.
Bindu.

Developer
Aug 29, 2008 at 1:56 PM

Hi

 

It sounds like there is a dependency in your NavigationView class that is not being injected (i.e.: like the presenter, a service, etc). Are you using the WorkItem to create that object instead of new? Try creating your view like this:

 

NavigationView view = WorkItem.SmartParts.AddNew<NavigationView>();

 

If you are still getting exceptions, can be useful if you provide us the code of the NavigationView class.

 

Please, let me know if it helps.

 

Mariano Converti

http://blogs.southworks.net/mconverti