Hi!
I have problem with passing data to custom action. I don't know what wrong
I'm doing. I'm trying to follow the steps in the walkthrough: "Passing Data
to a Custom Action"
http://msdn.microsoft.com/library/de...stomaction.asp
The error I recieve is:
"The savedSate dictionary does not contain the expected values and might
have been corrupt."
The code I'm using in the installer class is as follow:
public override void Install (System.Collections.IDictionary stateSaver)
{
//Get the parameter passed across in the CustomActionData
string strServerName = this.Context.Parameters["SNAME"];
if(strServerName == "")
throw new InstallException ("No arguments specified");
//Use reflection to find the location of the config file
Assembly Asm = Assembly.GetExecutingAssembly();
FileInfo fileInfo = new FileInfo(Asm.Location + ".config");
if (!fileInfo.Exists)
throw new InstallException ("Missing Config file");
//Load the config file into the XML DOM.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load (fileInfo.FullName);
//Finds the right node and change it to the new value
XmlNodeList nodelist = xmlDocument.GetElementsByTagName ("appSettings");
bool foundServerName = false;
for (int i = 0; i < nodelist.Count; i++)
{
int y = 0;
XmlNode n = nodelist[i].FirstChild;
while (y < nodelist[i].ChildNodes.Count)
{
if(n.Name == "add")
{
if (n.Attributes["key"].Value == "SNAME")
{
n.Attributes["value"].Value = strServerName;
foundServerName = true;
}
}
n = n.NextSibling;
y++;
}
}
if(!foundDataBaseName)
throw new InstallException ("config file did not contain a
servername section");
//Write out the new config file.
xmlDocument.Save (fileInfo.FullName);
}
thanks in advance.
---------------
Best regards
- Hans -
---------------
(Have fun programming with ... C#)