繁体   English   中英

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

[英]WPF application immediately closes for user

我有一个为我工作的公司构建的 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()发生了异常,但它是 static class。

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

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

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

编辑

TypeInitializationException只是告诉您 class 初始化失败。 Since Jmis is a static class, or depends on static classes, the static constructors and initializers get called before your IsUpdated method is called, and somewhere in the initialization of the Jmis class it is failing to find a file.

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

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

所以我已经这样做了,它似乎已经解决了这个问题。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM