【发布时间】:2017-05-14 11:42:06
【问题描述】:
所以我尝试为我的应用程序实现自动更新程序,from this thread。
我已将我的设置文件上传到我的服务器,当我尝试获取文件的 AssemblyVersion 时,我得到了 System.BadImageFormatException,更准确地说:
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 文件来做这个?
标签: c#