From 21ac92dd1dbf33d94b34020a3e43b52f30b1b115 Mon Sep 17 00:00:00 2001 From: Jose C Gomez Date: Mon, 17 Apr 2017 07:11:55 -0400 Subject: [PATCH] Added optional parameter to provide assembly for version checking. 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. --- AutoUpdater.NET/AutoUpdater.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/AutoUpdater.NET/AutoUpdater.cs b/AutoUpdater.NET/AutoUpdater.cs index fb89d3b7..e8f1e24c 100644 --- a/AutoUpdater.NET/AutoUpdater.cs +++ b/AutoUpdater.NET/AutoUpdater.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.Globalization; using System.IO; @@ -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. /// /// URL of the xml file that contains information about latest version of the application. - public static void Start(String appCast) + /// Assembly to use for version checking. + public static void Start(String appCast, Assembly myAssembly = null) { AppCastURL = appCast; @@ -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)); @@ -361,4 +362,4 @@ public class UpdateInfoEventArgs : EventArgs /// public Version InstalledVersion { get; set; } } -} \ No newline at end of file +}