Strange issue in .NET 4.8.1 WinForms app
Closed this issue · 2 comments
I have been using my own copy of this for sometime now, I modified to have a Preprocess batch file to allow me to clear down only specific files (*.DLL and *.EXE) and leave all the others.
Due to issues with other things I have removed this and installed the current version from Nuget.
I have come across a very strange issue with it in how I have implemented.
I have created the XML as always
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.2024.618.1350</version>
<url>https://.../mothership/Updates/Test/AppUpdates/BTPCaseManagement_1_2024_619_1000/Update.zip</url>
<changelog>https://.../mothership/Updates/Test/AppUpdates/BTPCaseManagement_1_2024_619_1000/Update.txt</changelog>
<mandatory>false</mandatory>
<args>--clear</args>
</item>
I do a update check in the app startup
[STAThread]
static void Main(string[] args)
{
AppHelper.CheckAppUpdate(false, true);
if (AppHelper.restartApp)
{
Application.Exit();
}
else
{
SingleInstanceApp myApp = new SingleInstanceApp();
myApp.Run(args);
}
}
The CheckAppUpdate method
public static void CheckAppUpdate(bool force = false, bool syncronous = false)
{
AutoUpdater.Mandatory = false;
AutoUpdater.ReportErrors = true;
AutoUpdater.ClearAppDirectory = false;
AutoUpdater.RunUpdateAsAdmin = false;
AutoUpdater.UpdateFormSize = new Size(600, 500);
if (force)
{
AutoUpdater.Mandatory = true;
}
AutoUpdater.Synchronous = syncronous;
//AutoUpdater.Start(settingsObjectGlobal.ApplicationUpdatePath);
AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;
AutoUpdater.Start("https://..../mothership/Updates/Test/WebUpdate.xml");
}
The Update Check event
public static void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
{
if (args?.Error == null)
{
if (args.IsUpdateAvailable)
{
if (args.InstallerArgs.Contains("--clear"))
{
AutoUpdater.ClearAppDirectory = true;
}
AutoUpdater.ApplicationExitEvent += AutoUpdater_ApplicationExitEvent;
AutoUpdater.ShowUpdateForm(args);
}
}
else
{
if (args.Error is WebException)
{
MessageBox.Show(
@"There is a problem reaching update server. Please check your internet connection and try again later.",
@"Update Check Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show(args.Error.Message,
args.Error.GetType().ToString(), MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
I am doing this because I need to determine if the directory should be cleared or not based on the XML config so I can push small patches with just a few files, I would toggle the --clear
The issue
if I have the entry in the XML <args>--clear</args> every thing works perfectly.
however
if I omit the entire args entry I get the following error and to fix it I have to have a blank args entry : <args></args>

Testing indicates the args is null, until I inspect it!
Ultimately the fix is to add the blank args but the args is supposed to be optional!
Ideas?
It is a strange issue indeed. I checked code and args should not be null in any case. Is it possible to provide the full stack trace or is it possible to reproduce this on a Test project, so I can check it out?
Turns out this is not an issue after all.
In Release mode, the error is as shown, in Debug I spotted I was testing the args.InstallerArgs args.InstallerArgs.Contains("--clear") However I did not realize, no args meant InstallerArgs would be null (of course it would be)
I added a test for null on the appropriate line and all is good.
Sorry, sometimes its too easy to miss the obvious!
if (!string.IsNullOrEmpty(args.InstallerArgs) && args.InstallerArgs.Contains("--clear"))
{
AutoUpdater.ClearAppDirectory = true;
}