So Im trying to implement a auto-updater for my application, from this thread.
I've uploaded my setup file to my server and when Im trying to get the AssemblyVersion of the file I get System.BadImageFormatException, more exactly:
System.BadImageFormatException occurred
HResult=0x8007000B
Message=Det går inte att läsa in filen eller sammansättningen Setup1.msi eller ett av dess beroenden. Ett försök att läsa in ett program med ogiltigt format gjordes.
Source=mscorlib
StackTrace:
at System.Reflection.AssemblyName.nGetFileInformation(String s)
at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
at WindowsFormsApp1.Form1..ctor() in C:\Users\Gustav\Documents\Visual Studio 2017\Projects\WindowsFormsApp1\WindowsFormsApp1\Form1.cs:line 50
at WindowsFormsApp1.Program.Main() in C:\Users\Gustav\Documents\Visual Studio 2017\Projects\WindowsFormsApp1\WindowsFormsApp1\Program.cs:line 22
Inner Exception 1:
BadImageFormatException: Det går inte att läsa in filen eller sammansättningen Setup1.msi eller ett av dess beroenden. Ett försök att läsa in ett program med ogiltigt format gjordes.
I've read that this is because of an x64 application trying to run a x86 DLL, but this shouldn't be the case since it's the exact same application im trying to get the info from?
string remoteUri = "http://<URL>/downloads/";
string fileName = "Setup1.msi", myStringWebResource = null;
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
myWebClient.DownloadFile(myStringWebResource, fileName);
if (AssemblyName.GetAssemblyName("Setup1.msi").Version > Assembly.GetExecutingAssembly().GetName().Version)
{
logger.Add("Update found!");
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "Setup1.msi";
Process.Start(startInfo);
this.Close();
}
My setup is x86 and the application is also x86.