Exception while raising propertychanged event in Muitiple view scenario

Topics: Prism v4 - Silverlight 4
May 3, 2014 at 8:38 AM
Edited May 3, 2014 at 8:40 AM
Hi,

I am working on windows store app and it has multiple view scenario where I publish one object from Main view to secondary view using Event Aggregator (PRISM). while assigning that object to a property of same type in subscriber class I receive below error.


A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.Practices.Prism.StoreApps.DLL

Additional information: Unable to cast COM object of type 'System.ComponentModel.PropertyChangedEventHandler' to class type 'System.ComponentModel.PropertyChangedEventHandler'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

If there is a handler for this exception, the program may be safely continued.



This error occurs in below property on line which is bold.
string _playingSong;
        public string PlayingSong
        {
            get { return _playingSong; }
            set
            {
                if (value != null)
                  SetProperty(ref _playingSong, value);
            }
        }
if I remove SetProperty and set field value directly as below, code doesn't throw any error. it looks like error occurs while raising propertychangedevent.
        string _playingSong;
        public string PlayingSong
        {
            get { return _playingSong; }
            set
            {
                if (value != null)
                    _playingSong = value;
            }
        }
I use PRISM to bind view with ViewModels.


Appreciate any help.
May 5, 2014 at 6:15 PM
Hi,

First of all, I would like to mention that Apps of Windows Store use another Prism project known as Prism for Windows Runtime. Therefore, questions for Windows Store Apps with Prism have their own forum site in order to keep track of them. The following Codeplex site corresponds to Prism for Windows Runtime:

Anyway, the error may be ocurring when assigning the value to the parameter variable. I would suggest you to raise the PropertyEventChanged event directly from the Property's set block statement, rigth after setting the value to the _playingSong variable as shown in the second code block.

I hope this helped you,
Regards.

Gabriel Ostrowsky
https://blogs.southworks.net/gostrowsky