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

时间:2019-11-12 15:06:24

标签: c# wpf

我有一个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();
    }

它向我显示CHECKING FOR UPDATES消息,然后关闭。

因此,我再次在Jmis.IsUpdated()方法内放了一些消息框:

    public static bool IsUpdated()
    {
        try
        {
            MessageBox.Show("Sending request");
            var response = Http.GetAsync($"{JmisUri}/toasterNotification/version.php").Result;
            MessageBox.Show("Ensuring success");
            response.EnsureSuccessStatusCode();
            MessageBox.Show("Getting version string");
            var version = response.Content.ReadAsStringAsync().Result;
            MessageBox.Show("Checking version");
            return version == Assembly.GetExecutingAssembly().GetName().Version.ToString();
        } 
        catch(Exception ex)
        {
            return true;
        }
    }

我至少期望Sending request出现。但事实并非如此。我仍然得到CHECKING FOR UPDATES,但除此之外什么都没有。

好像根本没有调用该方法。

我真的很沮丧。

有什么可能发生这种情况吗?

编辑

查看事件日志后,我发现了这一点:

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()的异常是一个静态类。

2 个答案:

答案 0 :(得分:3)

当我遇到这样的问题之前,它通常是缺少的库。我只能在这里猜测而没有更多信息,但是我猜测,当您调用IsUpdated时,它正在从using语句中加载其他库。

此人的机器上可能未安装预期已安装的软件。

您可以使用依赖项遍历器http://www.dependencywalker.com/来查看是否缺少库。

编辑

TypeInitializationException只是告诉您该类未能初始化。由于Jmis是静态类,或者取决于静态类,因此在调用IsUpdated方法之前会调用静态构造函数和初始化器,并且在Jmis类初始化的某处无法找到文件。

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

答案 1 :(得分:1)

好的,所以我认为,因为用户正在运行Windows 8.1,并且由于我的程序集针对.NET Framework 4.7.2,所以我可能必须安装该版本的.NET Framework。

所以我做到了,看来已经解决了这个问题。

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

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

相关问题