On Oct 1, 1:39*pm, Dinsdale <russ.ha...@gmail.comwrote:
We have created a object library that implements the
INotifyPropertyChanged.PropertyChanged to bubble changes up to higher
level classes. For instance, we have a person class that can have
relationships with other persons. If there is a change in the
relationship (i.e. status, type etc) then we want the PropertyChanged
event to fire and notify the top level Person object of that change.
The PropertyChanged event is implemented as follows:
Public Event PropertyChanged As PropertyChangedEventHandler Implements
INotifyPropertyChanged.PropertyChanged
I don't think you need the specific delegate handler to get the
picture (let me know if you do). Either way, I am now trying to use
the classes in a silverlight application that uses WCF. When I add the
ServiceReference to the silverlight project, the utility generates the
proxy classes for me and generates the following Property:
<System.Runtime.Serialization.DataMemberAttribute( IsRequired:=True)_
* * * * Public Property PropertyChangedEvent() As
System.ComponentModel.PropertyChangedEventHandler
* * * * * * Get
* * * * * * * * Return Me.PropertyChangedEventField
* * * * * * End Get
* * * * * * Set(ByVal value As
System.ComponentModel.PropertyChangedEventHandler)
* * * * * * * * If
(Object.ReferenceEquals(Me.PropertyChangedEventFie ld, Value) <True)
Then
* * * * * * * * * * Me.PropertyChangedEventField = Value
* * * * * * * * * * Me.RaisePropertyChanged("PropertyChangedEvent")
* * * * * * * * End If
* * * * * * End Set
* * * * End Property
The compiler then throws the following error:
property 'PropertyChangedEvent' conflicts with a member implicitly
declared for event 'PropertyChanged' in class 'ModelBaseClass'.
I am assuming the issue is because I have implemented the
INotifyChange.PropertyChangedEventHandler and the proxy class
generated uses the System.ComponentModel.PropertyChangedEventHandler,
but I am unsure what I should do to correct this issue as I don't have
control over the proxy class generation. The ObjectModel is compiled
under .Net 2.0 and the WCF project is using 3.5 and I am wondering if
this is could also affect the situation.
Any clarification would be greatly appreciated.
Sincerely,
D
Okay, I finally found the cause of this particular error. The
following link explains that "The Visual Basic compiler creates
implicit members corresponding to certain programming elements you
declare." Because I called my event PropertyChanged, and there is an
implicit member created called PropertyChangedEvent already created by
VB, when the AddService wizard generated the proxy class and named the
proxy property PropertyChangedEvent, there was a name collision. I
wonder if this would be an issue in C#? The link explaining the issue
is
http://msdn.microsoft.com/en-us/library/ms184639.aspx. Once I
changed the event name to ObjectPropertyChanged, everything compiled
Anyway, I'm getting an abstract 404 error now so I decided to create a
really simple test class to move forward. The class is as follows:
<Serializable()_
Public Class SimpleClass
Private _firstName As String
Private _lastName As String
Private _birthDate As Date
Public Property FirstName() As String
Get
Return _firstName
End Get
Set(ByVal value As String)
_firstName = value
End Set
End Property
Public Property LastName() As String
Get
Return _lastName
End Get
Set(ByVal value As String)
_lastName = value
End Set
End Property
Public Property BirthDate() As Date
Get
Return _birthDate
End Get
Set(ByVal value As Date)
_birthDate = value
End Set
End Property
End Class
This worked fine, so I added the INotifyChanged interface to my class:
Imports System.ComponentModel
<Serializable()_
Public Class SimpleClass
Implements INotifyPropertyChanged
Public Event ObjectPropertyChanged As PropertyChangedEventHandler
Implements INotifyPropertyChanged.PropertyChanged
....
Now I am getting the following exception:
Exception:
There was an error while trying to deserialize parameter
http://tempuri.org/:GetSimpleClassResult. Please see InnerException
for more details.
Inner Exception:
Type 'System.ComponentModel.PropertyChangedEventHandler ' cannot be
serialized. Consider marking it with the DataContractAttribute
attribute, and marking all of its members you want serialized with the
DataMemberAttribute attribute.
I'm reading through a WCF book as fast as I can, but there doesn't
seem to be anything about INotifyPropertyChanged issues in there. Once
again, I would really appreciate any clarification on this from some
of you MS gurus so I can get back at creating a proof of concept. This
is starting to look really bad and I'm going to have trouble
convincing my boss that that we should switch to Silverlight and WCF
if I don't get something working soon! (Please don't read that as
blame on the technology, it's just a fact that I've struggled to get
this running).
Cheers,
D