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

    Question

  • 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.


    SDhiraj

    Friday, May 2, 2014 5:41 AM

Answers

  • This is a PRISM question, and you'll find better answers at the official PRISM sites:

    https://compositewpf.codeplex.com/discussions


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, May 2, 2014 12:49 PM
    Moderator