Squirrel / Squirrel.Windows

An installation and update framework for Windows desktop apps
MIT License
7.42k stars 1.03k forks source link

UpdateManager.RestartApp() working but leaving an exception. #1371

Closed Sgtmoustache closed 5 years ago

Sgtmoustache commented 6 years ago

Hello.

When trying to restart our app after an update, we're receiving this exception. The restart still work but we want to ignore this exception. We cannot catch the exception.

System.Threading.Tasks.TaskCanceledException: A task was cancelled.

  private void TryUpdateApp(bool duringInit)
        {
            try
            {
                if (UpdateApp(duringInit).Result)
                {
                    EventBus.GetEvent<VersionUpdated>().Publish(true);

                    bool displayWindow;
                    lock (_ManualUpdateLock)
                    {
                        displayWindow = (_CommandLineOptions.ShowWindowOnBoot && duringInit)
                                        || _UpdateManuallyApproved;
                    }

                    string args = string.Format("{0} {1}",
                        CommandLineOptions.OptionStrings.LaunchedByUpdateRestart,
                        displayWindow
                            ? CommandLineOptions.OptionStrings.ShowWindowOnBoot
                            : CommandLineOptions.OptionStrings.HideWindowOnBoot);

                    UpdateManager.RestartApp(null, args);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to check for updates: " + ex.Message);
            }
        }

Is it Squirrel who is creating this task and cancelling it?

Thanks you.

anaisbetts commented 6 years ago

Is it Squirrel who is creating this task and cancelling it?

No idea! You didn't post a call stack

Sgtmoustache commented 6 years ago

No idea! You didn't post a call stack

The thing is, it seems like there is no useful call stack information.

mscorlib.dll | System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
mscorlib.dll | System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification 
WindowsBase.dll | System.Windows.Threading.DispatcherOperation.Wait
WindowsBase.dll | System.Windows.Threading.Dispatcher.InvokeImpl
WindowsBase.dll | System.Windows.Threading.Dispatcher.Invoke
WindowsBase.dll | MS.Internal.WeakEventTable.OnShutDown
WindowsBase.dll | MS.Internal.ShutDownListener.HandleShutDown

There is no way for me to know what's happening inside Squirrel.

Thanks for you help.

anaisbetts commented 6 years ago

Do you have a repro for this crash? You probably want to run with first-chance exceptions enabled

RichardD2 commented 6 years ago

I believe I've just encountered the same issue. The update is downloaded successfully, and the new version is used when the application restarts. But the UpdateManager.UpdateApp call terminates with a TaskCancelledException, with no useful information in the stack trace.

Squirrel was also not cleaning up older versions, as mentioned in #1347.

After downgrading Mono.Cecil from 0.10.0 to 0.9.6.4, I am no longer getting the exception, and older versions are being cleaned up properly again.

Sgtmoustache commented 6 years ago

@RichardD2 , Interresting, I don't think that our app is using Mono.Cecil... do you know what was causing the bug with this package? Also, I just realise that our app is also not cleaning any older version. For each version, I have a .full and a .delta.

@paulcbetts , I tried running the same bug with first-chance exceptions enables and still, there's no usefull information. Everytime I restart my app with Squirrel (after a full launch), I get this error.

Do you think that this could be related in anyway?

RichardD2 commented 6 years ago

@Sgtmoustache My app doesn't use Mono.Cecil either. But Squirrel does, so you end up with a reference to the NuGet package anyway.

Sgtmoustache commented 6 years ago

Oh I see! I will try this thank you!

Sgtmoustache commented 6 years ago

@RichardD2 , Wait... how do you downgrade the dependence of the Squirrel nuget package?

RichardD2 commented 6 years ago

@Sgtmoustache You'll need to add an explicit package reference for the packages you want to downgrade, and specify the older version.

You might also need to check the binding redirects in your config file, if any, to make sure they're specifying the correct version.

JustinKaffenberger commented 6 years ago

I can also attest to the TaskCanceledException occurring. My application is successfully updated, but RestartApp does not restart the application. Upon the next boot of my application it is up to date and successfully boots the application.

rog1039 commented 6 years ago

To add some further information: I experienced the same issues as the above. The update is sort of successful since my app is on the latest version after I restart the app a second time--the first restart I am still on the old version. I did get a stack trace from my logging code. It is included below.

My Mono.Cecil has also been updated to version 0.10.1 via nuget. I haven't tried downgrading yet to 0.9.6.0. Will do that next.

Stack trace:

System.IO.FileLoadException: Could not load file or assembly 'Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'
   at Squirrel.SquirrelAwareExecutableDetector.GetAssemblySquirrelAwareVersion(String executable)
   at Squirrel.SquirrelAwareExecutableDetector.<>c__DisplayClass1_0.<GetPESquirrelAwareVersion>b__0() in C:\Users\paulb\code\Squirrel\squirrel.windows\src\Squirrel\SquirrelAwareExecutableDetector.cs:line 33
   at Squirrel.Utility.Retry[T](Func`1 block, Int32 retries) in C:\Users\paulb\code\Squirrel\squirrel.windows\src\Squirrel\Utility.cs:line 158
   at Squirrel.SquirrelAwareExecutableDetector.GetPESquirrelAwareVersion(String executable) in C:\Users\paulb\code\Squirrel\squirrel.windows\src\Squirrel\SquirrelAwareExecutableDetector.cs:line 32
   at Squirrel.SquirrelAwareExecutableDetector.<>c__DisplayClass0_0.<GetAllSquirrelAwareApps>b__2(String x) in C:\Users\paulb\code\Squirrel\squirrel.windows\src\Squirrel\SquirrelAwareExecutableDetector.cs:line 23
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Squirrel.SquirrelAwareExecutableDetector.GetAllSquirrelAwareApps(String directory, Int32 minimumVersion) in C:\Users\paulb\code\Squirrel\squirrel.windows\src\Squirrel\SquirrelAwareExecutableDetector.cs:line 20
   at Squirrel.UpdateManager.ApplyReleasesImpl.<invokePostInstall>d__10.MoveNext() in C:\Users\paulb\code\Squirrel\squirrel.windows\src\Squirrel\UpdateManager.ApplyReleases.cs:line 377
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Squirrel.Utility.<LogIfThrows>d__42.MoveNext() in C:\Users\paulb\code\Squirrel\squirrel.windows\src\Squirrel\Utility.cs:line 615
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Squirrel.UpdateManager.ApplyReleasesImpl.<ApplyReleases>d__2.MoveNext() in C:\Users\paulb\code\Squirrel\squirrel.windows\src\Squirrel\UpdateManager.ApplyReleases.cs:line 59
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Squirrel.UpdateManager.<ApplyReleases>d__9.MoveNext() in C:\Users\paulb\code\Squirrel\squirrel.windows\src\Squirrel\UpdateManager.cs:line 73
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

<< I removed the rest of the stack trace that includes my code >>

Thieum commented 5 years ago

@shiftkey duplicate of #1337. This can be closed.