因此,我試圖爲我的應用程序實現自動更新,from this thread。System.BadImageFormatException得到AssemblyVersion時
我已經上傳安裝文件到我的服務器,當我試着去獲取文件,我得到System.BadImageFormatException,更確切的的AssemblyVersion:
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.
我讀過,這是因爲一個x64應用程序試圖運行一個x86 DLL,但這不應該是這種情況,因爲它是完全相同的應用程序試圖從中獲取信息?
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();
}
我的設置是x86,應用程序也是x86。
的.msi不是.NET文件,你爲什麼會用'AssemblyVersion'檢查呢? –
哇,我很愚蠢,所以用.msi文件做這件事是不可能的? –
[使用'FileVersionInfo'](http://stackoverflow.com/a/1537764/107625)怎麼樣? –