這個問題可能是相當本地化的,但我真的需要另一種意見,我在這裏做錯了什麼。在流程的每個階段,如何將非法字符傳遞到臨時文件,一切看起來都很正常?非法字符在路徑之謎
我得到這個:
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()?
是的,我記錄了行的每一側,只執行時命中第一個。
試試這個:@「C:\ Documents and Settings \ SRanson \ Local Setti ngs \ Temp \ 1 \ tmp1E0.tmp「 –
我假設你的字符串實際上並不包含」「,因爲」>「和」<「是路徑中的無效字符;) –
@VictorMukherjee:我想過這個,實際上,字符串甚至不會編譯,因爲它會有無法識別的轉義序列(\ D,\ S,\ L,\ T,\ 1) –