我的 WPF 应用程序在 VS2015 中以调试模式成功运行。但是,在不调试的情况下启动时,应用程序启动并立即完成。从 Debug/Release 文件夹启动 exe 文件时也会发生同样的情况。
事件查看器显示以下 .Net 运行时错误:
应用程序:Cisco.exe 框架版本:v4.0.30319 说明:
由于未处理的异常,进程被终止。异常信息:
System.InvalidOperationException 位于
MS.Internal.Data.PropertyPathWorker.CheckReadOnly(System.Object,
系统.对象)位于
MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32,System.Object,
系统.对象)位于
MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32,
System.ComponentModel.ICollectionView、System.Object、布尔值)位于
MS.Internal.Data.ClrBindingWorker.AttachDataItem() 位于
System.Windows.Data.BindingExpression.Activate(System.Object) 在
System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt)
在
System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(布尔值)
在 MS.Internal.Data.DataBindEngine+Task.Run(Boolean) 处
MS.Internal.Data.DataBindEngine.Run(System.Object) 位于
System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,
System.Object,Int32)位于
System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object,
System.Delegate、System.Object、Int32、System.Delegate)位于
System.Windows.Threading.DispatcherOperation.InvokeImpl() 在
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、布尔值)位于
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,
System.Threading.ContextCallback、System.Object、布尔值)位于
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,
System.Threading.ContextCallback、System.Object)位于
MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext,
System.Threading.ContextCallback、System.Object)位于
System.Windows.Threading.DispatcherOperation.Invoke() 在
System.Windows.Threading.Dispatcher.ProcessQueue() 在
System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr,
IntPtr,布尔 ByRef)在 MS.Win32.HwndWrapper.WndProc(IntPtr,Int32,
IntPtr、IntPtr、布尔 ByRef)位于
MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)位于
System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,
System.Object,Int32)位于
System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object,
System.Delegate、System.Object、Int32、System.Delegate)位于
System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,
System.TimeSpan、System.Delegate、System.Object、Int32)位于
MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
在
MS.Win32.UnsafeNativeMethods.MessageBox(System.Runtime.InteropServices.HandleRef,
系统.String、系统.String、Int32)位于
System.Windows.MessageBox.ShowCore(IntPtr, System.String,
System.String、System.Windows.MessageBoxButton、
系统.Windows.MessageBoxImage、系统.Windows.MessageBoxResult、
System.Windows.MessageBoxOptions)位于
System.Windows.MessageBox.Show(System.String) 位于
Cisco.App.OnStartup(System.Windows.StartupEventArgs) 位于
System.Windows.Application.<.ctor>b__1_0(System.Object) 位于
System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,
System.Object,Int32)位于
System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object,
System.Delegate、System.Object、Int32、System.Delegate)位于
System.Windows.Threading.DispatcherOperation.InvokeImpl() 在
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、布尔值)位于
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,
System.Threading.ContextCallback、System.Object、布尔值)位于
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,
System.Threading.ContextCallback、System.Object)位于
MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext,
System.Threading.ContextCallback、System.Object)位于
System.Windows.Threading.DispatcherOperation.Invoke() 在
System.Windows.Threading.Dispatcher.ProcessQueue() 在
System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr,
IntPtr,布尔 ByRef)在 MS.Win32.HwndWrapper.WndProc(IntPtr,Int32,
IntPtr、IntPtr、布尔 ByRef)位于
MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)位于
System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,
System.Object,Int32)位于
System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object,
System.Delegate、System.Object、Int32、System.Delegate)位于
System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,
System.TimeSpan、System.Delegate、System.Object、Int32)位于
MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
在
MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG
通过参考)在
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)位于
System.Windows.Application.Run(System.Windows.Window)位于
Cisco.App.Main()
我知道有很多问题都有同样的问题,但还没有解决方案可以解决我的问题。
在运行期间主窗口甚至不出现。因此,我将所有 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 https://drive.google.com/open?id=16USjjKwxsQsmOOhacY2uilwfXWkBZVOx到谷歌驱动器。也许它会更有用。