我正在尝试将安装状态文件中的信息传递给安装程序类,然后卸载它。
但在传递之前,我需要将信息转换为System.Collections.IDictionary savedState。
为此,是否可以反序列化安装状态文件?
答案 0 :(得分:1)
如果您使用AssemblyInstaller类,会出现(虽然这似乎没有记录),它通常会忽略任何传递的{{1}而是代替处理savedState
文件(在安装期间编写,在卸载期间读取它)。
如果您因某些原因无法使用它,您可以使用反汇编工具从其INSTALLSTATE
方法中提取必要的代码以执行反序列化(我相信,它看起来如此,所使用的特定序列化方法因.NET版本而异,因此我建议使用适合您当前正在使用的.NET版本的方法。
这是Uninstall
方法,从System.Configuration.Install(文件版本4.6.1590.0)反编译:
Uninstall
您会注意到它没有使用传递给它的任何内容public override void Uninstall(IDictionary savedState)
{
this.PrintStartText(Res.GetString("InstallActivityUninstalling"));
if (!this.initialized)
{
this.InitializeFromAssembly();
}
string installStatePath = this.GetInstallStatePath(this.Path);
if ((installStatePath != null) && File.Exists(installStatePath))
{
FileStream input = new FileStream(installStatePath, FileMode.Open, FileAccess.Read);
XmlReaderSettings settings = new XmlReaderSettings {
CheckCharacters = false,
CloseInput = false
};
XmlReader reader = null;
if (input != null)
{
reader = XmlReader.Create(input, settings);
}
try
{
if (reader != null)
{
NetDataContractSerializer serializer = new NetDataContractSerializer();
savedState = (Hashtable) serializer.ReadObject(reader);
}
goto Label_00C6;
}
catch
{
object[] args = new object[] { this.Path, installStatePath };
base.Context.LogMessage(Res.GetString("InstallSavedStateFileCorruptedWarning", args));
savedState = null;
goto Label_00C6;
}
finally
{
if (reader != null)
{
reader.Close();
}
if (input != null)
{
input.Close();
}
}
}
savedState = null;
Label_00C6:
base.Uninstall(savedState);
if ((installStatePath != null) && (installStatePath.Length != 0))
{
try
{
File.Delete(installStatePath);
}
catch
{
object[] objArray2 = new object[] { installStatePath };
throw new InvalidOperationException(Res.GetString("InstallUnableDeleteFile", objArray2));
}
}
}
- 当它将该变量用于任何内容时(此处,将其传递给基类),它& #39;或者从savedSate
文件覆盖它,或者将INSTALLSTATE
分配给它。