MethodAccessException未处理

时间:2018-02-15 20:54:22

标签: c# wpf

好的我有一个WPF程序可以在一台计算机上运行但不能在另一台计算机上运行。在另一个,我得到这个MethodAccessException是未处理的

当问题调用NotifyPropertyChanged():

public abstract class NotifyChanged: INotifyPropertyChanged {

    #region INotifyPropertyChanged
    /// <summary>
    /// PropertyChanged can be triggered whenever a Property changes value.
    /// It is also available for classes which inherit from 
    MachineComponent.
    /// </summary>
    public virtual event PropertyChangedEventHandler PropertyChanged;

    /// <summary>
    /// NotifyPropertyChanged can be called explicitly, by sending the name 
     of the property as a string,
    /// or implicitly, by calling it without parameters from the Property 
    that changes.
    /// </summary>
    /// <param name="info"></param>
    [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", 
   "CA1026:DefaultParametersShouldNotBeUsed" )]
    protected void NotifyPropertyChanged( [CallerMemberName] string info = "none passed" ) {
        if ( PropertyChanged != null ) {
            PropertyChanged( this, new PropertyChangedEventArgs( info ) );
        }
    }
    #endregion
谁知道为什么?

我被告知此代码来自Microsoft网站

更新..我正在添加完整的错误消息。现在这是运行时错误消息

完整的错误消息:

System.MethodAccessException was unhandled
 HResult=-2146233072
 Message=Attempt by method 
'Moxtek.XRF.Core.LocationViewModel.set_LocationName(System.String)' to 
 access method 
 'Moxtek.Common.Abstract.NotifyChanged.NotifyPropertyChanged(System.String)' 
  failed.
  Source=Moxtek.XRF.Core
  StackTrace:
   at Moxtek.XRF.Core.LocationViewModel.set_LocationName(String value) in C:\Users\lolsen\Source\XRF\Moxtek.XRF.Core\ViewModels\MeasurementRecipeViewModels\LocationViewModel.cs:line 41
   at Moxtek.XRF.Core.LocationViewModel..ctor(XrfLocationSet location, LocationItemViewModel locationItem, MeasurementRecipeItemViewModel recipeItem, IDataObject`1 locationData, IServiceLocator services) in C:\Users\lolsen\Source\XRF\Moxtek.XRF.Core\ViewModels\MeasurementRecipeViewModels\LocationViewModel.cs:line 12
   at Moxtek.XRF.Core.LocationItemViewModel.GetItems() in C:\Users\lolsen\Source\XRF\Moxtek.XRF.Core\ViewModels\MeasurementRecipeViewModels\LocationItemViewModel.cs:line 36
   at Moxtek.XRF.Core.LocationItemViewModel..ctor(IDataObject`1 locationData, MeasurementRecipeItemViewModel recipeItem, IServiceLocator services) in C:\Users\lolsen\Source\XRF\Moxtek.XRF.Core\ViewModels\MeasurementRecipeViewModels\LocationItemViewModel.cs:line 14
   at Moxtek.XRF.Core.XrfViewModel..ctor(ChartingViewModel chart, IServiceLocator services) in C:\Users\lolsen\Source\XRF\Moxtek.XRF.Core\ViewModels\XrfViewModel.cs:line 29
   at Moxtek.XRF.WPF.App.OnStartup(StartupEventArgs e) in C:\Users\lolsen\Source\XRF\Moxtek.XRF.WPF\App.xaml.cs:line 46
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at Moxtek.XRF.WPF.App.Main()
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
   at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
   at System.Activator.CreateInstance(ActivationContext activationContext)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
   InnerException:

0 个答案:

没有答案