我的WPF应用程序在调试模式下成功运行在VS2015中。但是,在没有调试应用程序启动时启动并立即完成。从Debug / Release文件夹启动exe文件时也会发生同样的情况。 事件查看器显示以下.Net运行时错误:
应用程序:Cisco.exe Framework版本:v4.0.30319描述: 由于未处理的异常,进程被终止。例外信息: System.InvalidOperationException at MS.Internal.Data.PropertyPathWorker.CheckReadOnly(System.Object的, System.Object)at MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32,System.Object, System.Object)at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(的Int32, System.ComponentModel.ICollectionView,System.Object,Boolean)at MS.Internal.Data.ClrBindingWorker.AttachDataItem()at System.Windows.Data.BindingExpression.Activate(System.Object)at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt) 在 System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(布尔) 在MS.Internal.Data.DataBindEngine + Task.Run(布尔)处 MS.Internal.Data.DataBindEngine.Run(System.Object)at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object,Int32)at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object的, System.Delegate,System.Object,Int32,System.Delegate)at System.Windows.Threading.DispatcherOperation.InvokeImpl()at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object的) 在 MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object的) 在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,Boolean)at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,Boolean)at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object)at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback,System.Object)at System.Windows.Threading.DispatcherOperation.Invoke()at System.Windows.Threading.Dispatcher.ProcessQueue()at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr, IntPtr,布尔ByRef)在MS.Win32.HwndWrapper.WndProc(IntPtr,Int32, IntPtr,IntPtr,Boolean ByRef)at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)at at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object,Int32)at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object的, System.Delegate,System.Object,Int32,System.Delegate)at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan,System.Delegate,System.Object,Int32)at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr) 在 MS.Win32.UnsafeNativeMethods.MessageBox(System.Runtime.InteropServices.HandleRef, System.String,System.String,Int32)at System.Windows.MessageBox.ShowCore(IntPtr,System.String, System.String,System.Windows.MessageBoxButton, System.Windows.MessageBoxImage,System.Windows.MessageBoxResult, System.Windows.MessageBoxOptions)at System.Windows.MessageBox.Show(System.String)at Cisco.App.OnStartup(System.Windows.StartupEventArgs)at System.Windows.Application。< .ctor> b__1_0(System.Object)at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object,Int32)at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object的, System.Delegate,System.Object,Int32,System.Delegate)at System.Windows.Threading.DispatcherOperation.InvokeImpl()at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object的) 在 MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object的) 在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,Boolean)at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,Boolean)at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object)at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback,System.Object)at System.Windows.Threading.DispatcherOperation.Invoke()at System.Windows.Threading.Dispatcher.ProcessQueue()at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr, IntPtr,布尔ByRef)在MS.Win32.HwndWrapper.WndProc(IntPtr,Int32, IntPtr,IntPtr,Boolean ByRef)at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)at at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object,Int32)at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object的, System.Delegate,System.Object,Int32,System.Delegate)at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan,System.Delegate,System.Object,Int32)at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr) 在 MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 在 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) 在System.Windows.Application.RunDispatcher(System.Object)处 System.Windows.Application.RunInternal(System.Windows.Window)at System.Windows.Application.Run(System.Windows.Window)at Cisco.App.Main()
我知道有很多问题存在同样的问题,但还没有解决方案解决了我的问题。
在运行期间,MainWindow甚至不会出现。所以我将所有OnStartup方法移动到try catch块,尝试使用MessageBox识别此异常,但MessageBox也不会出现。
public partial class App : Application
{
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
e.Handled = true;
}
protected override void OnStartup(StartupEventArgs e)
{
try
{
base.OnStartup(e);
Ioc.Setup();
Current.MainWindow = new MainWindow();
Current.MainWindow.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
我已将完整的solution上传到Google云端硬盘。也许它会更有用。
答案 0 :(得分:1)
最后我找到了原因。 问题与使用私有setter的twoWay绑定到公共变量有关。制作此setter之后,公共应用程序成功运行。