Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF应用程序立即为用户关闭_C#_Wpf - Fatal编程技术网

C# WPF应用程序立即为用户关闭

C# WPF应用程序立即为用户关闭,c#,wpf,C#,Wpf,我有一个WPF应用程序是为我工作的公司开发的。在我的机器和分支网络中的其他机器上,所有这些都非常有效 然而,我们总部有一个用户不能使用它。应用程序启动后立即关闭。我试图在任务管理器中监视它,它出现了,然后立即关闭 因此,我决定在启动表单中放置一些消息框,以查看失败的地方: public LoginWindow() { MessageBox.Show("CHECKING FOR UPDATES"); var updated = Jmis.IsUpda

我有一个WPF应用程序是为我工作的公司开发的。在我的机器和分支网络中的其他机器上,所有这些都非常有效

然而,我们总部有一个用户不能使用它。应用程序启动后立即关闭。我试图在任务管理器中监视它,它出现了,然后立即关闭

因此,我决定在启动表单中放置一些消息框,以查看失败的地方:

    public LoginWindow()
    {
        MessageBox.Show("CHECKING FOR UPDATES");
        var updated = Jmis.IsUpdated();
        MessageBox.Show("UPDATES CHECKED");
        if (updated)
        {
            MessageBox.Show("LOADING SETTINGS");
            Settings = FileManager.LoadSettings();
            MessageBox.Show("SETTINGS LOADED");
            this.DataContext = Settings;
            InitializeComponent();
            Password.Password = Settings.Password;
        }
        else
        {
            MessageBox.Show("A new version is available!", "Update", MessageBoxButton.OK, MessageBoxImage.Information);
            new UpdateWindow().Show();
            Close();
        }
        InitializeComponent();
    }
它显示“检查更新”消息,然后关闭

因此,我再次在Jmis.IsUpdated方法中添加了一些MessageBox:

我至少期待着发出请求。但事实并非如此。我仍然得到更新检查,但没有其他

就好像根本没有调用该方法一样

我真的被难住了

这有什么原因吗

编辑

查看事件日志后,我发现:

Application: JMIS Notifier.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at JMIS_Notifier.JMIS.Jmis..cctor()

Exception Info: System.TypeInitializationException
   at JMIS_Notifier.JMIS.Jmis.IsUpdated()
   at JMIS_Notifier.LoginWindow..ctor()

Exception Info: System.Windows.Markup.XamlParseException
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
   at System.Windows.Application.LoadComponent(System.Uri, Boolean)
   at System.Windows.Application.DoStartup()
   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)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at 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, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(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.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at System.Windows.Application.Run()
   at JMIS_Notifier.App.Main()

有趣的是,异常发生在JMIS_Notifier.JMIS.JMIS..cctor,但它是一个静态类。

当我遇到这样的问题时,它通常是一个缺少的库。我只能在这里猜测,没有更多的信息,但我猜当您调用isupdate时,它正在从您的using语句加载额外的库

有可能预期安装的软件未安装在此人的计算机上

您可以使用依赖项查询器查看是否缺少库

编辑 TypeInitializationException只是告诉您类初始化失败。由于Jmis是一个静态类,或者依赖于静态类,因此在调用IsUpdated方法之前会调用静态构造函数和初始值设定项,而在Jmis类的初始化过程中,它找不到文件


因此,很可能与Jmis相关的东西没有安装,或者Jmis正在查找的某些资源在出现故障的机器上不可用。

当我遇到类似问题时,它通常是一个缺少的库。我只能在这里猜测,没有更多的信息,但我猜当您调用isupdate时,它正在从您的using语句加载额外的库

有可能预期安装的软件未安装在此人的计算机上

您可以使用依赖项查询器查看是否缺少库

编辑 TypeInitializationException只是告诉您类初始化失败。由于Jmis是一个静态类,或者依赖于静态类,因此在调用IsUpdated方法之前会调用静态构造函数和初始值设定项,而在Jmis类的初始化过程中,它找不到文件


因此,很可能没有安装与Jmis相关的内容,或者Jmis正在查找的某些资源在出现故障的计算机上不可用。

好的,因此我认为这是因为用户运行的是Windows 8.1,而且我的程序集的目标是.NET Framework 4.7.2,我可能必须安装该版本的.NET Framework

所以我这样做了,似乎解决了这个问题

我只是觉得很奇怪,通常当你试图打开应用程序时,应用程序会告诉你需要某个.NET Framework版本


也许这与我正在使用Costura.Fody将依赖项合并到可执行文件中的事实有关。

好的,所以我认为,因为用户运行的是Windows 8.1,而且我的程序集的目标是.NET Framework 4.7.2,所以我可能必须安装该版本的.NET Framework

所以我这样做了,似乎解决了这个问题

我只是觉得很奇怪,通常当你试图打开应用程序时,应用程序会告诉你需要某个.NET Framework版本


也许这与我使用Costura.Fody将依赖项合并到可执行文件中有关。

查看系统事件日志。那里应该有一条错误消息。为什么要调用InitializeComponent;在登录窗口?从表面上看,可能有很多错误。您是否正确地浏览了Jmis.IsUpdated;?你…吗?这种情况下最常见的原因是不能加载引用的程序集,因为它没有安装B。它依赖于未安装的其他DLL或C,它要求操作系统为64位,但操作系统是32位或副。versa@NineBerry我已经贴出了答案这似乎解决了我们的一个用户的问题。我将很快为其他用户测试它。查看系统事件日志。那里应该有一条错误消息。为什么要调用InitializeComponent;在登录窗口?从表面上看,可能有很多错误。您是否正确地浏览了Jmis.IsUpdated;?你…吗?远程数据块
这个行为的最常见的原因是因为没有安装一个引用的程序集,因为它没有被安装,它依赖于没有安装的其他DLL或者C,它要求操作系统是64位,但是操作系统是32位或是副。versa@NineBerry我已经发布了一个答案似乎已经为我们的一个用户解决了这个问题。我将很快为其他用户测试它。除了使用dependency walker,当问题是加载托管程序集而不是本机DLL时,您可以使用它来分析问题。@Christopher应用程序没有显示此类异常,因此我感到困惑。即使在您指出的方法中,我在捕获后返回true,如果我将MessageBox显示ex.Message,它也不会显示。@Christopher它正在抛出一个异常,该异常现在已包含在问题中,但在调用IsUpdate之前抛出,因此,他的try-catch根本没有吞下它,因为它从来没有到达他的try-catch block.IIRC,当框架应用程序在没有附加调试器的情况下遇到异常时,框架本身将捕获它并将其显示在一个巨大的消息框中。框架本身就是最终的回退暴露器如果他只是在事件日志中发现,而不是让框架将异常细节推到用户面前,那么似乎有些不可思议的错误但是,FileNotFound通常是缺少库的指示器。同样,链接的例子是,你的情况是正确的。我只需要安装应用程序所针对的.NET Framework。这是我能想到的唯一一件事,因为我正在使用Costura.Fody将其他依赖项合并到可执行文件中。我只是觉得奇怪,我没有收到任何迹象表明它缺少适当的框架。除了使用dependency walker之外,当问题是加载托管程序集而不是本机DLL时,您可以使用它来分析问题。@Christopher应用程序没有给出这种异常的迹象,因此我感到困惑。即使在您指出的方法中,我在捕获后返回true,如果我将MessageBox显示ex.Message,它也不会显示。@Christopher它正在抛出一个异常,该异常现在已包含在问题中,但在调用IsUpdate之前抛出,因此,他的try-catch根本没有吞下它,因为它从来没有到达他的try-catch block.IIRC,当框架应用程序在没有附加调试器的情况下遇到异常时,框架本身将捕获它并将其显示在一个巨大的消息框中。框架本身就是最终的回退暴露器如果他只是在事件日志中发现,而不是让框架将异常细节推到用户面前,那么似乎有些不可思议的错误但是,FileNotFound通常是缺少库的指示器。同样,链接的例子是,你的情况是正确的。我只需要安装应用程序所针对的.NET Framework。这是我能想到的唯一一件事,因为我正在使用Costura.Fody将其他依赖项合并到可执行文件中。我只是觉得奇怪,我没有收到任何迹象表明它缺少适当的框架。
Application: JMIS Notifier.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at JMIS_Notifier.JMIS.Jmis..cctor()

Exception Info: System.TypeInitializationException
   at JMIS_Notifier.JMIS.Jmis.IsUpdated()
   at JMIS_Notifier.LoginWindow..ctor()

Exception Info: System.Windows.Markup.XamlParseException
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
   at System.Windows.Application.LoadComponent(System.Uri, Boolean)
   at System.Windows.Application.DoStartup()
   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)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at 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, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(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.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at System.Windows.Application.Run()
   at JMIS_Notifier.App.Main()