Windows phone 7 windows phone 7的本地数据库应用中NotifyPropertyChanged的MissingMethodException

Windows phone 7 windows phone 7的本地数据库应用中NotifyPropertyChanged的MissingMethodException,windows-phone-7,inotifypropertychanged,missingmethodexception,Windows Phone 7,Inotifypropertychanged,Missingmethodexception,在为Winows Phone 7.1制作MVC应用程序时,我一直遵循MSDN教程作为参考: 在我的应用程序中,我在表中有一个对象,该对象实现了INotifyPropertyChanged和INotifyPropertyChanged接口,并具有如下属性: private DateTime lastViewDate; [专栏] 公共日期时间LastViewDate { 获取{return lastViewDate;} 设置 { 如果(lastViewDate!=值) { NotifyProper

在为Winows Phone 7.1制作MVC应用程序时,我一直遵循MSDN教程作为参考:

在我的应用程序中,我在表中有一个对象,该对象实现了INotifyPropertyChanged和INotifyPropertyChanged接口,并具有如下属性:

private DateTime lastViewDate;
[专栏]
公共日期时间LastViewDate
{
获取{return lastViewDate;}
设置
{
如果(lastViewDate!=值)
{
NotifyPropertyChange(“LastViewDate”);
lastViewDate=值;
NotifyPropertyChanged(“LastViewDate”);
}
}
}
更改LastViewDate属性时,调用NotifyPropertyChange时会引发MissingMethodException,即使该属性显然存在。那么我做错了什么? (我是wp7编程的noob,所以这可能是显而易见的,只是对我来说不是)

编辑:更多信息

下面是接口方法,其中添加了一些用于检查方法的调用:

//用于通知属性即将更改
私有void notifyPropertyChangeg(字符串propertyName)
{
var type=this.GetType();
var method=type.GetMethod(propertyName);//null
var getMethod=type.getMethod(“get_3;”+propertyName);//有效
var setMethod=type.GetMethod(“set_u3;”+propertyName);//有效
var methods=type.GetMethods();//set_LastViewDate在方法列表中
//
if(PropertyChange!=null)
{
PropertyChange(这是新的PropertyChangingEventArgs(propertyName));
}
}
将调用更改为NotifyPropertyChange(“set_LastViewDate”);仍然给出了相同的例外。(并且“方法”在调试类型检查中为null)

编辑:

堆栈跟踪:

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)
System.MissingMethodException未处理
Message=MissingMethodException
堆栈跟踪:
位于System.Activator.InternalCreateInstance(类型类型、布尔非公共、StackScrawlMark和stackMark)
位于System.Activator.CreateInstance(类型)
位于System.Data.Linq.WorkAround.ActivationHelper.CreateInstance(类型)
位于System.Data.Linq.ChangeTracker.StandardChangeTracker.StandardTrackeObject.CreateDataCopy(对象实例)
在System.Data.Linq.ChangeTracker.StandardChangeTracker.StandardTrackeObject.StartTracking()中
位于System.Data.Linq.ChangeTracker.StandardChangeTracker.OnPropertyChange(对象发送器、PropertyChangeEventArgs args args)
在WindowsPhonePlaces.Photo.notifyPropertyChangeg(字符串propertyName)
在WindowsPhonePlaces.Photo.set_LastViewDate(日期时间值)
在WindowsPhonePlaces.Photo.ResetViewDate()上
在WindowsPhonePlaces.PhotoViewerPage.on导航到(NavigationEventArgs e)
位于Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedTo(NavigationEventArgs e)
在System.Windows.Navigation.NavigationService.RaiseNavigated(对象内容、Uri、NavigationMode模式、布尔值isNavigationInitiator、PhoneApplicationPage existingContentPage、PhoneApplicationPage newContentPage)
位于System.Windows.Navigation.NavigationService.CompleteNavigation(依赖对象内容,导航模式)
在System.Windows.Navigation.NavigationService.ContentLoader\u BeginLoad\u回调中(IAsyncResult结果)
在System.Windows.Navigation.PageResourceContentLoader.BeginLoad\u OniThread(异步回调用户回调,PageResourceContentLoaderAsyncResult结果)
在System.Windows.Navigation.PageResourceContentLoader.c__DisplayClass4.b__0(对象参数)中
在System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi、对象obj、BindingFlags invokeAttr、绑定器绑定器、对象参数、CultureInfo区域性、布尔值isBinderDefault、程序集调用者、布尔值验证访问、堆栈爬网标记和堆栈标记)
位于System.Reflection.RuntimeMethodInfo.InternalInvoke(对象obj、BindingFlags invokeAttr、绑定绑定器、对象[]参数、CultureInfo区域性、StackScrawMark和stackMark)
在System.Reflection.MethodBase.Invoke(对象obj,对象[]参数)处
位于System.Delegate.DynamicInvokeOne(对象[]args)
位于System.MulticastDelegate.DynamicInvokeImpl(对象[]args)
位于System.Delegate.DynamicInvoke(对象[]args)
在System.Windows.Threading.DispatcherOperation.Invoke()中
在System.Windows.Threading.Dispatcher.Dispatch中(DispatcherPriority优先级)
位于System.Windows.Threading.Dispatcher.OnInvoke(对象上下文)
位于System.Windows.Hosting.CallbackCookie.Invoke(对象[]args)
位于System.Windows.Hosting.DelegateWrapper.InternalInvoke(对象[]args)
位于System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle、Int32 nParamCount、ScriptParam[]pParams、ScriptParam&pResult)

物业变更是否已公开?如果不是,则应将其设置为公共。

我将此解决方案作为一个单独的答案放在这里,以明确说明:

问题是我将构造函数设置为私有,并使用静态方法创建db对象。这不适用于LINQ——您需要一个无参数的公共构造函数


多亏@Metro Smurf和@Rajeev Nair找到了答案。

您在
notifyPropertyChange
方法中尝试如何处理反射?代码中还存在其他问题;你发布的所有内容都会起作用。您可以发布堆栈跟踪吗?我试图表明,当我通过调试检查问题时,我可以通过反射看到它声称缺少的方法(我的'methods'变量具有'LastViewDate'的getter和setter)。我假设框架订阅了我的PropertyChange事件,然后在尝试使用反射访问属性时崩溃。(由于某种原因,框架无法像我一样看到属性,并且崩溃了——这就是我感到困惑的原因…)我怀疑这与
System.Data.Linq
有关。你的类是否有一个空构造函数?i、 例如,
publicYourClass(){}
as