简体   繁体   中英

WPF application immediately closes for user

I have a WPF application I built for the company I work for. The whole things works great on my machine and other machines in the branch network.

However, we have a user here at head office who cannot use it. The application immediately closes upon startup. I tried to monitor it in Task Manager, and it appears, and then closes right away.

So, I decided to put some message boxes in the startup form to see where it fails:

    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();
    }

It shows me the CHECKING FOR UPDATES message, and then closes.

So again, I put some more messageboxes inside the Jmis.IsUpdated() method:

    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;
        }
    }

I was at least expecting Sending request to come up. But it didn't. I still get the CHECKING FOR UPDATES , but nothing else.

It's as if that method isn't being called at all.

I'm genuinely stumped.

Is there any reason this might happen?

EDIT

After looking at the Event Log, I found this:

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()

What's interesting is the exception occurs at JMIS_Notifier.JMIS.Jmis..cctor() but is a static class.

When I have run into problems like this before it is usually a missing library. I can only guess here without more information, but I'm guessing that when you call IsUpdated it is loading additional libraries at that point from your using statements.

It may be possible that there is software that is expected to be installed that is not installed on this person's machine.

You can use a dependency walker http://www.dependencywalker.com/ to see if you are missing a library.

Edit

The TypeInitializationException Is just telling you that the class failed to initialize. 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.

So, most likely something related to Jmis is not installed, or there is some resource that Jmis is looking for that is not available on the machine that is failing.

Okay, so I figured that because the user was running Windows 8.1, and because my assembly targets .NET Framework 4.7.2, that I might have to install that version of .NET Framework.

So I have done that and it seems to have solved the issue.

I just find it strange, usually the application will tell you that you need a certain .NET Framework version when you try to open it.

Perhaps it has something to do with the fact that I'm using Costura.Fody to merge the dependencies into the executable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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