wpf应用程序在调试模式下运行,但在没有调试的情况下不会运行

0_d*_*day 2 c# wpf visual-studio-2015

我的 WPF 应用程序在 VS2015 中以调试模式成功运行。但是,在不调试的情况下启动时,应用程序启动并立即完成。从 Debug/Release 文件夹启动 exe 文件时也会发生同样的情况。事件查看器显示以下 .Net 运行时错误:

应用程序:Cisco.exe 框架版本:v4.0.30319 描述:由于未处理的异常,进程被终止。异常信息:MS.Internal.Data.PropertyPathWorker.CheckReadOnly(System.Object,System.Object)处的System.InvalidOperationException MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32,System.Object,System.Object)处的MS.Internal .Data.PropertyPathWorker.UpdateSourceValueState(Int32, System.ComponentModel.ICollectionView, System.Object, Boolean) 在 MS.Internal.Data.ClrBindingWorker.AttachDataItem() 在 System.Windows.Data.BindingExpression.Activate(System.Object) 在系统.Windows.Data.BindingExpression.AttachToContext(AttachAttempt) 在 System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean) 在 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.委托、System.Object、Int32、System.Delegate)在 System.Windows.Threading.DispatcherOperation.InvokeImpl() 在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) 在 MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.对象)在 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, Boolean 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、System.String、System.String、Int32) 在 System.Windows.MessageBox.ShowCore(IntPtr、System.String、System.String、

我知道有很多问题都有同样的问题,但还没有解决方案可以解决我的问题。

在运行期间主窗口甚至不出现。因此,我将所有 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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我已将完整的解决方案上传到谷歌驱动器。也许它会更有用。

0_d*_*day 5

终于我找到了原因。该问题与使用私有 setter 绑定到公共变量有关。使此 setter 公共应用程序成功运行后。