I have been following the MSDN tutorial as a reference while making an MVC app for Winows Phone 7.1: http://msdn.microsoft.com/en-us/library/hh286405(v=vs.92).aspx
In my app, I have an object in a table that implements the INotifyPropertyChanging and INotifyPropertyChanged interfaces implemented and a property like this:
private DateTime lastViewDate;
[Column]
public DateTime LastViewDate
{
get { return lastViewDate; }
set
{
if (lastViewDate != value)
{
NotifyPropertyChanging("LastViewDate");
lastViewDate = value;
NotifyPropertyChanged("LastViewDate");
}
}
}
When the LastViewDate property gets changed, a MissingMethodException gets thrown when NotifyPropertyChanging gets called even though the property is obviously there. So what am I doing wrong? (I'm a noob at wp7 programming so it might be obvious, just not to me)
EDIT: more info
Here is the interface method with some added calls to examine the methods:
// Used to notify that a property is about to change
private void NotifyPropertyChanging(string propertyName)
{
var type = this.GetType();
var method = type.GetMethod(propertyName); // null
var getMethod = type.GetMethod("get_" + propertyName); // works
var setMethod = type.GetMethod("set_" + propertyName); // works
var methods = type.GetMethods(); // set_LastViewDate is in the method list
//
if (PropertyChanging != null)
{
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
}
Changing the call to NotifyPropertyChanging("set_LastViewDate"); still gives the same exception. (and 'method' gets null in the debug type checking)
EDIT:
Stack trace:
System.MissingMethodException was unhandled
Message=MissingMethodException
StackTrace:
at System.Activator.InternalCreateInstance(Type type, Boolean nonPublic, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type)
at System.Data.Linq.WorkAround.ActivationHelper.CreateInstance(Type type)
at System.Data.Linq.ChangeTracker.StandardChangeTracker.StandardTrackedObject.CreateDataCopy(Object instance)
at System.Data.Linq.ChangeTracker.StandardChangeTracker.StandardTrackedObject.StartTracking()
at System.Data.Linq.ChangeTracker.StandardChangeTracker.OnPropertyChanging(Object sender, PropertyChangingEventArgs args)
at WindowsPhonePlaces.Photo.NotifyPropertyChanging(String propertyName)
at WindowsPhonePlaces.Photo.set_LastViewDate(DateTime value)
at WindowsPhonePlaces.Photo.ResetViewDate()
at WindowsPhonePlaces.PhotoViewerPage.OnNavigatedTo(NavigationEventArgs e)
at Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedTo(NavigationEventArgs e)
at System.Windows.Navigation.NavigationService.RaiseNavigated(Object content, Uri uri, NavigationMode mode, Boolean isNavigationInitiator, PhoneApplicationPage existingContentPage, PhoneApplicationPage newContentPage)
at System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject content, NavigationMode mode)
at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)
at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result)
at System.Windows.Navigation.PageResourceContentLoader.<>c__DisplayClass4.<BeginLoad>b__0(Object args)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
I'm putting the solution as a separate answer here to make it clear:
The problem was that I made the constructor private and used a static method to create my db objects. This doesn't work with LINQ--you need a parameterless, public constructor.
Thanks to @Metro Smurf and @Rajeev Nair for figuring it out.