App.Current.Dispatcher.Invoke((Action)(() =>
{
myCollection.Add(measurement);
}));
我将一个Measurement对象添加到ObservableCollection<Measurement>
并得到&#34;类型为'System.Reflection.TargetException' occurred in mscorlib.dll
的第一次机会异常
其他信息:Object does not match target type.
&#34;
我不明白为什么会被抛出,因为它们都是同一类型。 堆栈跟踪:
mscorlib.dll!System.Reflection.RuntimeMethodInfo.CheckConsistency(object target) Unknown
System.dll!System.SecurityUtils.MethodInfoInvoke(System.Reflection.MethodInfo method, object target, object[] args) Unknown
System.dll!System.ComponentModel.ReflectPropertyDescriptor.GetValue(object component) Unknown
DevExpress.Data.v14.2.dll!DevExpress.Data.Browsing.RelatedDataBrowser.RetrieveDataSource() Unknown
DevExpress.Data.v14.2.dll!DevExpress.Data.Browsing.DataBrowser.DataSource.get() Unknown
DevExpress.Data.v14.2.dll!DevExpress.Data.Browsing.DataBrowser.Current.get() Unknown
DevExpress.Data.v14.2.dll!DevExpress.Data.Browsing.RelatedDataBrowser.RetrieveDataSource() Unknown
DevExpress.Data.v14.2.dll!DevExpress.Data.Browsing.DataBrowser.DataSource.get() Unknown
DevExpress.Data.v14.2.dll!DevExpress.Data.Browsing.DataBrowser.Current.get() Unknown
DevExpress.Charts.v14.2.Core.dll!DevExpress.Charts.Native.SeriesBindingProcedure.CreateBindingPoints() Unknown
DevExpress.Xpf.Charts.v14.2.dll!DevExpress.Xpf.Charts.Series.UpdateSeriesBinding(object dataSource) Unknown
DevExpress.Xpf.Charts.v14.2.dll!DevExpress.Xpf.Charts.Diagram.UpdateBinding() Unknown
DevExpress.Xpf.Charts.v14.2.dll!DevExpress.Xpf.Charts.ChartControl..ctor.AnonymousMethod__c() Unknown
DevExpress.Xpf.Charts.v14.2.dll!DevExpress.Xpf.Charts.Native.BindingBehavior.DataSourceChanged(object sender, System.EventArgs e) Unknown
System.dll!System.Collections.ObjectModel.ObservableCollection<Data.Measurement>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) Unknown
System.dll!System.Collections.ObjectModel.ObservableCollection<System.__Canon>.InsertItem(int index, System.__Canon item) Unknown
mscorlib.dll!System.Collections.ObjectModel.Collection<Data.Measurement>.Add(Data.Measurement item) Unknown
> MyApp.exe!MyApp.Data.ViewModels.CompleteMeasurementsViewModel.MeasurementAddedFromDevice.AnonymousMethod__29() Line 293 C#
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeDelegateCore() Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) Unknown
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() Unknown
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Unknown
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Unknown
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) Unknown
PresentationFramework.dll!System.Windows.Application.Run() Unknown
MyApp.exe!App.Main() C#
[Native to Managed Transition]
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) Unknown
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() Unknown
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) Unknown
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Unknown
一致性检查崩溃了吗?奇怪的是,这并没有发生。请介绍一下这个
编辑:
如果我继续打击继续我会得到这个例外:
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
其他信息:Property accessor 'Vehicle' on object 'Location' threw the following exception:'Object does not match target type.'
这篇文章中的情景似乎与我的相似...... http://www.thecodingforums.com/threads/gridview-object-does-not-match-target-type-error-during-binding-collection-of-different-type-objec.121226/