문제

This question might be quite localised, but I really need another opinion on what I'm doing wrong here. How can I be passing illegal characters in a path to a temporary file when at every stage of the process, everything appears to be fine and normal?

I'm getting this:

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

When passing this:

"C:\Documents and Settings\<username>\Local Settings\Temp\1\tmp1E0.tmp"

to this:

XmlDocument doc = new XmlDocument();
doc.Load(<above string>);

The file exists in the location specified (I've checked it during execution) although System.IO.File.Exists thinks otherwise; I cannot see anything obvious. Is there anything I could try to work around it?

More code available upon request:

REQ1: How is your path being declared?

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);
}

The session variable is passed around to various locations, but is not altered.

REQ2: Are you actually using <username>?

No, I edited it out. It's a valid windows username.

REQ3: What do you get back from debugging?

This is actually happening within an installer (which is slightly difficult to physically debug) but the above string is an example from what I can get from the logs, with the valid username, of course.

REQ4: More code on how it's used?

I'm adding the WiX tag because this involves WiX3.7.

Basic Data holding class:

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

    public SessionState()
    {
        //Setting of properties
    }
}

From within the Form:

//StringBuilder for arguments
installerargs.Append("\" TEMPCONFIGDIR=\"");
installerargs.Append(m_Session.TempConfigDir);
//...
Process p = Process.Start("msiexec", installerargs.ToString());
p.WaitForExit();

APPEND: Part missed from Form:

//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);

From within WiX3.7's 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=&quot;[TEMPCONFIGDIR]&quot;;" />

From Within the Custom Action that uses it:

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: Do you change the TempConfigDir variable to something.xml?

No, I copy an xml file over the exact name/directory that's supplied (including .tmp).

REQ6: Are you sure it's happening on .Load()?

Yes, I've logged each side of the line and only hit the first one when executing.

도움이 되었습니까?

해결책

This line seems suspect:

<CustomAction Id="CA_InstallUICA.SetProp" Property="CA_InstallUICA" Value="rcswebdir=[MCWSVDIR];webdir=[WEBAPPVDIR];installtype=notransaction;targetdir=[INSTALLDIR];interaction=[INTERACTION];tempconfigdir=&quot;[TEMPCONFIGDIR]&quot;;" />

The portion quoting the path appears likely to be doubling the quotes, thus producing the exception:

tempconfigdir=&quot;[TEMPCONFIGDIR]&quot;

Remove the &quote; wrapping to deliver the actual path:

tempconfigdir=[TEMPCONFIGDIR]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top