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.