Skip to content

Commit

Permalink
Added optional parameter to provide assembly for version checking.
Browse files Browse the repository at this point in the history
Added an optional parameter to Start method, this allows you to pass in the Assembly you'd like to use for version checking. The original was failing when the assembly that needed to be checked was called from a main.exe via a dynamic plugin.
Specifically, a Microsoft Office VSTO plugin that I wanted to auto update, when using the original code the GetEntryAssembly() call failed and returned null.
  • Loading branch information
josegomez authored and ravibpatel committed Apr 17, 2017
1 parent 932f95e commit 21ac92d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -107,7 +107,8 @@ public static void Start()
/// Start checking for new version of application and display dialog to the user if update is available.
/// </summary>
/// <param name="appCast">URL of the xml file that contains information about latest version of the application.</param>
public static void Start(String appCast)
/// <param name="myAssembly">Assembly to use for version checking.</param>
public static void Start(String appCast, Assembly myAssembly = null)
{
AppCastURL = appCast;

Expand All @@ -117,12 +118,12 @@ public static void Start(String appCast)

backgroundWorker.DoWork += BackgroundWorkerDoWork;

backgroundWorker.RunWorkerAsync();
backgroundWorker.RunWorkerAsync(myAssembly ?? Assembly.GetEntryAssembly());
}

private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
{
Assembly mainAssembly = Assembly.GetEntryAssembly();
Assembly mainAssembly = e.Argument as Assembly;
var companyAttribute =
(AssemblyCompanyAttribute) GetAttribute(mainAssembly, typeof (AssemblyCompanyAttribute));
var titleAttribute = (AssemblyTitleAttribute) GetAttribute(mainAssembly, typeof (AssemblyTitleAttribute));
Expand Down Expand Up @@ -361,4 +362,4 @@ public class UpdateInfoEventArgs : EventArgs
/// </summary>
public Version InstalledVersion { get; set; }
}
}
}

0 comments on commit 21ac92d

Please sign in to comment.