Crash on AppLoaded

I'm following the automatic updater backend tutorial and somewhere in my testing, i'm getting a strange behaviour, it seems that the automatic updater is crashing on the auBackend.Apploaded function without exception.

My OnStart code looks like this:

protected override void OnStart(string[] args) { try { Logger.WriteInfo("On Start Server"); Logger.WriteInfo("Guid: " + Assembly.GetExecutingAssembly().GetType().GUID); Logger.WriteInfo("ServiceName: " + this.ServiceName); // setup the automatic updater to update and report to webserver SomeServer._auBackend = new AutomaticUpdaterBackend { GUID = Assembly.GetExecutingAssembly().GetType().GUID.ToString(), UpdateType = UpdateType.Automatic, ServiceName = this.ServiceName }; Logger.WriteInfo("Created updater backend"); SomeServer._auBackend.ReadyToBeInstalled += OnReadyToBeInstalled;

Logger.WriteInfo("Initializing..."); OzDocsServer._auBackend.Initialize(); Logger.WriteInfo("Loading..."); OzDocsServer._auBackend.AppLoaded(); Logger.WriteInfo("Finished auto updater event handlers");

// run the service in another thread so the OnStart can return within the timeout this._mainWorker = new BackgroundWorker(); this._mainWorker.DoWork += StartSomeServerWorker; this._mainWorker.RunWorkerAsync(); Logger.WriteInfo("Running main worker"); } catch(Exception e) { this._exceptionHandler.HandleException(e);} }

Running this, the last print statement i see is "Loading...", I don't get the next print statement.

What's perculiar is that this exact code has worked. I'm having problems getting the rest of the automatic silent service update to work so I was playing around with moving versions of files etc... and now AppLoaded is playing up. What does this function do and what could be the potential cause of this? I'm not getting any exceptions either otherwise they would also be printed out.

Restarting doesn't help.

The first thing you should do is attach a debugger to your service and see what exception is thrown. You can do this by adding this function in your service:

/// <summary>/// Helper function to attach a debugger to the running service./// </summary>[Conditional("DEBUG")]static void DebugMode(){    if (!Debugger.IsAttached)        Debugger.Launch();


    Debugger.Break();}

Then, at the beginning of your OnStart() method, add a call to DebugMode().

Looking at your code, everything looks good except this line:

GUID = Assembly.GetExecutingAssembly().GetType().GUID.ToString()

You're getting a GUID of the Assembly object type? Huh? I don't know if this is causing your crash, but it certainly looks wrong. I'm fairly certain this "Type.GUID" property will change from execution to execution (which is not what you want). Change this to:

GUID = "companyname-appname"

Or you can generate a GUID in Visual Studio by clicking the "Tools" menu and clicking "Create GUID".

Tell me what exceptions you get after attaching the debugger and running your service again.

Thanks for the debug mode code, that'll come in handy. And for picking up on my GUID string, it does look very wrong.

However, not sure how that will pick up any exceptions as I've explicitly put a try catch around the whole OnStart function and didn't pick up anything in the log. And i've also put logging messages around the culprit to prove the AppLoaded is the one it's stuck on.I've mentioned this in my original post.

I've now resorted to use the command line method of calling wyupdate.exe /fromservice and it works so gonna leave issue uninvestigated for the moment.

Thanks for the coding tips.

The AppLoaded function is where pending updates are detected and installed. If you don't use the auBackend.ClosingForInstall property and the auBackend_ReadyToBeInstalled event then this closing procedure could cause problems with any background threads you have running. In other words, you need to ensure your threads play nice when the AutomaticUpdater tries to close.

And i've also put logging messages around the culprit to prove the AppLoaded is the one it's stuck on.

You're not flushing the output. In other words, "Finished auto updater event handlers" could be written to the stream, but never written to the file because the something later crashes your service before the data is flushed to disk. So either flush the stream to file after every write call to find where the crash really is happening, or attach a debugger to your service to get the full crash details (see the code I posted).

I just realised that the DebugMode code posted is for a local service. I'm running this service on a vmimage and debugging it remotely. So I can't seem to attach to the break() statement.Using the commandline method seems to work fine so i'm happy to stick with this path. Is there any difference between running the automatic updater backend and the commandline?

The reason I note this is that i've had random bad read 0 and other errors from using the AutomaticUpdater.dll in my winform application (not all the time and not frequent but enough to be a problem). Numerous times, i've had to manually find the temp extracted files and clear the cache which a customer will not be expected to do.The silent commandline approach has worked consistently so we are adopting this for all our products that self update.

Is there any difference between running the automatic updater backend and the commandline?

The AutomaticUpdater gives you more control -- but in the grand scheme of things, no, there's no difference.

The reason I note this is that i've had random bad read 0 and other errors from using the AutomaticUpdater.dll in my winform application (not all the time and not frequent but enough to be a problem).

We can't reproduce that here. If you report it to us, we'll fix it. But we need a way to reproduce it. Or at the very least a crash report.