Application Error

Feb 1, 2012 at 3:11 AM
Edited Feb 1, 2012 at 3:12 AM


I have implemented a feature using ViewModelDetailBase that shows a ChildWindow to edit an entity to edit the properties. I have used Notify event and in the code behind, instantiated the childwindow view and set the datacontext with the passed in model data (parameter).


        /// <summary>
        /// Edits the selected treatment module.
        /// </summary>
        public void EditTreatmentModule()
                string type = SelectedAppliedTreatment.GetType().ToString();
                string modeltype = type.Substring(type.LastIndexOf('.') + 1);
                       new NotificationEventArgs<ITreatment, bool>
                           (modeltype, SelectedAppliedTreatment, Calculate));
            catch (Exception)

                MessageBox.Show("Cannot cast the to desired object.");
        private void Calculate(bool enable)
            EnableRemoveTreatments = enable;


void vm_EditTreatmentNotice(object sender, NotificationEventArgs<ITreatment, bool> e)
		  switch (e.Message)
				case "TreatmentModel":
					var tViewModel = new TreatmentViewModel(e.Data as TreatmentModel);
					var tView = new TreatmentView(tViewModel);
					tView.Closed += (s, ea) => e.Completed(true);

This works fine when I am running in my development machine using visual studio 2010. 

I then published this to IIS server (also my development machine running XP SP3). The application runs fine until I click the EDIT button which fires the Notify event with the model data. I get an Application Error.

It says:


"Application has generated an exception that could not be handled.

Process ID =0x11bc(4540), Thread ID=0x8e4 (2276)

Click OK to terminate the application.

Click CANCEL to debug the application."


I have no idea what went wrong as it work fine when I running in my machine.

I have implemented the same method for opening up a file in childwindow and it works fine. 

Any clues as to what must have gone wrong?

Your help is highly appreciated. Thanking you in advance.

Feb 3, 2012 at 1:55 AM
Are you accessing a database? You might want to check that your app pool identity has permission to the database.
Feb 3, 2012 at 2:13 AM

Hi Tony,

No, I am not using any database in my project except for the member database.

I have solved this problem now.

What I did:

  • Created a MasterTreatmentModel that holds all information of the treatments
  • Moved the collection of treatments from viewmodel to MasterTreatmentModel along with other properties
  • Exposed the MasterTreatmentModel in viewmodel and associate properties that would perform calculation in 'get' and then set the value in the corresponding property in the model
  • Kept the SelectedTreatment in the viewmodel

For some reason, it works and does not crash when editing the selected treatment.

Thank you once again. I fee a lot comfortable implementing MVVM using your toolkit. Its taken a long time but I think its all workth it in the end. Still learning ;-)