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.Collect ions.IDictionar y stateSaver)
{
//Get the parameter passed across in the CustomActionDat a
string strServerName = this.Context.Pa rameters["SNAME"];
if(strServerNam e == "")
throw new InstallExceptio n ("No arguments specified");
//Use reflection to find the location of the config file
Assembly Asm = Assembly.GetExe cutingAssembly( );
FileInfo fileInfo = new FileInfo(Asm.Lo cation + ".config");
if (!fileInfo.Exis ts)
throw new InstallExceptio n ("Missing Config file");
//Load the config file into the XML DOM.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Loa d (fileInfo.FullN ame);
//Finds the right node and change it to the new value
XmlNodeList nodelist = xmlDocument.Get ElementsByTagNa me ("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.Cou nt)
{
if(n.Name == "add")
{
if (n.Attributes["key"].Value == "SNAME")
{
n.Attributes["value"].Value = strServerName;
foundServerName = true;
}
}
n = n.NextSibling;
y++;
}
}
if(!foundDataBa seName)
throw new InstallExceptio n ("config file did not contain a
servername section");
//Write out the new config file.
xmlDocument.Sav e (fileInfo.FullN ame);
}
thanks in advance.
---------------
Best regards
- Hans -
---------------
(Have fun programming with ... C#)