C# 路径神秘中的非法角色

C# 路径神秘中的非法角色,c#,.net,exception,wix,.net-2.0,C#,.net,Exception,Wix,.net 2.0,这个问题可能有点局部化,但我真的需要另一种意见来说明我做错了什么。在进程的每一个阶段,一切看起来都很正常,我怎么能在临时文件的路径中传递非法字符呢 我明白了: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Illegal characters in path. 通过此项

这个问题可能有点局部化,但我真的需要另一种意见来说明我做错了什么。在进程的每一个阶段,一切看起来都很正常,我怎么能在临时文件的路径中传递非法字符呢

我明白了:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Illegal characters in path.
通过此项时:

“C:\Documents and Settings\\Local Settings\Temp\1\tmp1E0.tmp”

为此:

XmlDocument doc = new XmlDocument();
doc.Load(<above string>);
会话变量会传递到各个位置,但不会更改

REQ2:您实际使用的是

不,我删掉了。这是一个有效的windows用户名

REQ3:调试后你得到了什么

这实际上是在安装程序中发生的(物理调试有点困难),但是上面的字符串是我从日志中得到的一个示例,当然是有效的用户名

REQ4:关于如何使用它的更多代码

我添加WiX标签是因为它涉及WiX3.7

基本资料持有类别:

public class SessionState
{
    //<other properties>
    public string TempConfigDir { get; set; }

    public SessionState()
    {
        //Setting of properties
    }
}
附加:表单中缺少的部分:

从WiX3.7的MSI中:

<Property Id="TEMPCONFIGDIR" Value="UNSET" />
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=&quot;[TEMPCONFIGDIR]&quot;;" />
删除
"e包装以传递实际路径:

tempconfigdir=[TEMPCONFIGDIR]

试试这个:@“C:\Documents and Settings\SRanson\Local Settings\Temp\1\tmp1E0.tmp”我假设你的字符串实际上不包含“”,因为“>”和“@VictorMukherjee:我考虑过这个问题,但实际上,这个字符串甚至不会编译,因为它会有无法识别的转义序列(\D、\S、\L、\t、\1)如果您的文件路径是由
path.GetTempFileName()
直接创建的,那么我不确定发生了什么。您是否调试并确认在点击
doc.Load
时您没有转换/修改该路径?这让我想知道:
tempconfigdir=“[tempconfigdir]“
…路径是否已被引用,从而使引号加倍?或者在命令行调用中获取更多引号?
<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=&quot;[TEMPCONFIGDIR]&quot;;" />
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
<CustomAction Id="CA_InstallUICA.SetProp" Property="CA_InstallUICA" Value="rcswebdir=[MCWSVDIR];webdir=[WEBAPPVDIR];installtype=notransaction;targetdir=[INSTALLDIR];interaction=[INTERACTION];tempconfigdir=&quot;[TEMPCONFIGDIR]&quot;;" />
tempconfigdir=&quot;[TEMPCONFIGDIR]&quot;
tempconfigdir=[TEMPCONFIGDIR]