这个问题可能是非常本地化的,但我真的需要另外就我在这里做错了什么。如何在流程的每个阶段将非法字符传递到临时文件的路径中,一切似乎都很正常?
我得到了这个:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Illegal characters in path.
传递时:
"C:\Documents and Settings\<username>\Local Settings\Temp\1\tmp1E0.tmp"
到此:
XmlDocument doc = new XmlDocument();
doc.Load(<above string>);
该文件存在于指定的位置(我在执行期间检查过它),尽管System.IO.File.Exists
认为不是这样;我看不出任何明显的东西。有什么我可以尝试解决它吗?
根据要求提供更多代码:
REQ1: 您的路径是如何申报的?
try
{
session.TempConfigDir = System.IO.Path.GetTempFileName();
//All work done with the temp file happens within the Form
Form currentform = new WelcomeDialog(session);
DialogResult dr = currentform.ShowDialog();
}
finally
{
File.Delete(session.TempConfigDir);
}
会话变量传递到不同的位置,但不会改变。
REQ2: 您实际使用的是<username>
吗?
不,我把它编辑出来了。这是一个有效的Windows用户名。
REQ3: 您从调试中得到了什么?
这实际上是在安装程序中发生的(这在物理调试上有点困难),但上面的字符串是我从日志中获得的一个例子,当然还有有效的用户名。
REQ4: 有关如何使用的更多代码?
我正在添加WiX标签,因为这涉及到WiX3.7。
基本数据保持类:
public class SessionState
{
//<other properties>
public string TempConfigDir { get; set; }
public SessionState()
{
//Setting of properties
}
}
从表格中:
//StringBuilder for arguments
installerargs.Append("\" TEMPCONFIGDIR=\"");
installerargs.Append(m_Session.TempConfigDir);
//...
Process p = Process.Start("msiexec", installerargs.ToString());
p.WaitForExit();
APPEND:部分错过了表单:
//It's grabbing the web.config from an existing install
//and copying it over the temp file, not changing its location or name.
File.Copy(m_Session.INSTALLDIR + DIR_WEB_CONFIG, m_Session.TempConfigDir, true);
来自WiX3.7的MSI:
<Property Id="TEMPCONFIGDIR" Value="UNSET" />
...
<Custom Action="CA_InstallUICA.SetProp" After="StartServices">NOT Installed</Custom>
<Custom Action="CA_InstallUICA" After="CA_InstallUICA.SetProp">NOT Installed</Custom>
...
<CustomAction Id="CA_InstallUICA.SetProp" Property="CA_InstallUICA" Value="rcswebdir=[MCWSVDIR];webdir=[WEBAPPVDIR];installtype=notransaction;targetdir=[INSTALLDIR];interaction=[INTERACTION];tempconfigdir="[TEMPCONFIGDIR]";" />
从使用它的自定义操作中:
wz.AutoSettings.TempConfigLocation = session.CustomActionData["tempconfigdir"];
//Where I get the above string passed out
session.Log(wz.AutoSettings.TempConfigLocation);
//The rest of the code that uses it is above and where the exception is thrown
REQ5: 您是否将TempConfigDir变量更改为something.xml?
不,我将xml文件复制到提供的确切名称/目录上(包括.tmp
)。
REQ6: 你确定它正在发生.Load()吗?
是的,我已经记录了该行的每一行,并且在执行时只点击了第一行。
答案 0 :(得分:2)
这条线似乎很可疑:
<CustomAction Id="CA_InstallUICA.SetProp" Property="CA_InstallUICA" Value="rcswebdir=[MCWSVDIR];webdir=[WEBAPPVDIR];installtype=notransaction;targetdir=[INSTALLDIR];interaction=[INTERACTION];tempconfigdir="[TEMPCONFIGDIR]";" />
引用路径的部分似乎可能会使引号加倍,从而产生异常:
tempconfigdir="[TEMPCONFIGDIR]"
删除"e;
包装以提供实际路径:
tempconfigdir=[TEMPCONFIGDIR]