非法字符在路径之谜
问题描述:
这个问题可能是相当本地化的,但我真的需要另一种意见,我在这里做错了什么。在流程的每个阶段,如何将非法字符传递到临时文件,一切看起来都很正常?非法字符在路径之谜
我得到这个:
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>);
的文件中指定的位置存在(I”已经在执行过程中检查过它),但System.IO.File.Exists
认为otherwis Ë;我看不到任何明显的东西。有什么我可以尝试解决它吗?
代码:
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();
附加:部分来自晶错过:
//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()?
是的,我记录了行的每一侧,只执行时命中第一个。
答
此行似乎疑:
<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]
试试这个:@“C:\ Documents and Settings \ SRanson \ Local Setti ngs \ Temp \ 1 \ tmp1E0.tmp“ –
我假设你的字符串实际上并不包含”“,因为”>“和”
@VictorMukherjee:我想过这个,实际上,字符串甚至不会编译,因为它会有无法识别的转义序列(\ D,\ S,\ L,\ T,\ 1) –