【发布时间】:2013-08-27 17:39:13
【问题描述】:
Sitrep:我有一个解析函数,可以将数组中的多个文本解析为值。我连续多次进行相同类型的解析,前 3 次有效,而后两次在我尝试构建时在 Xamarin 中引发错误。我已经经历了好几次,但无法弄清楚它们有什么问题。
错误:
System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
at Microsoft.Samples.Debugging.CorDebug.NativeApi.ICorDebug.CreateProcess(String lpApplicationName, String lpCommandLine, SECURITY_ATTRIBUTES lpProcessAttributes, SECURITY_ATTRIBUTES lpThreadAttributes, Int32 bInheritHandles, UInt32 dwCreationFlags, IntPtr lpEnvironment, String lpCurrentDirectory, STARTUPINFO lpStartupInfo, PROCESS_INFORMATION lpProcessInformation, CorDebugCreateProcessFlags debuggingFlags, ICorDebugProcess& ppProcess)
at Microsoft.Samples.Debugging.CorDebug.CorDebugger.CreateProcess(String applicationName, String commandLine, SECURITY_ATTRIBUTES processAttributes, SECURITY_ATTRIBUTES threadAttributes, Boolean inheritHandles, Int32 creationFlags, IntPtr environment, String currentDirectory, STARTUPINFO startupInfo, PROCESS_INFORMATION& processInformation, CorDebugCreateProcessFlags debuggingFlags)
at Microsoft.Samples.Debugging.CorDebug.CorDebugger.CreateProcess(String applicationName, String commandLine, String currentDirectory, IDictionary`2 environment, Int32 flags)
at MonoDevelop.Debugger.Win32.CorDebuggerSession.<>c__DisplayClass5.<OnRun>b__4()
at MonoDevelop.Debugger.Win32.MtaThread.Run(Action ts)
at MonoDevelop.Debugger.Win32.CorDebuggerSession.OnRun(DebuggerStartInfo startInfo)
at Mono.Debugging.Client.DebuggerSession.<>c__DisplayClass11.<Run>b__f()
现在我已经查看了这个错误,并且我已经阅读了它,但是我对它的理解还不够,无法做出任何解释。对我来说,Xamarin 似乎找不到调试构建所需的文件,因此我尝试在 Xamarin 上进行修复安装,但这没有帮助。
代码
for (int i = 0; i < lines.Length; i++) {
string s = lines[i];
bool p;
// Some other parsing stuff
else if (s.Contains("Melee:")) {
int myMelee;
p = int.TryParse(s.Replace("Melee:", "").Trim(), out myMelee);
currentMek.melee = myMelee;
mekMelee.Value = currentMek.melee;
}
else if (s.Contains("Guns:")) {
int myGuns;
p = int.TryParse(s.Replace("Guns:", "").Trim(), out myGuns);
currentMek.guns = myGuns;
mekGuns.Value = currentMek.guns;
}
else if (s.Contains("Cannons:")) {
int myCannons;
p = int.TryParse(s.Replace("Cannons:", "").Trim(), out myCannons);
currentMek.cannons = myCannons;
mekCannons.Value = currentMek.cannons;
}
//causing problems from here down
else if (s.Contains("Missiles:")) {
int myMissiles;
p = int.TryParse(s.Replace("Missiles:", "").Trim(), out myMissiles);
currentMek.missiles = myMissiles;
mekMissiles.Value = currentMek.missiles;
}
else if (s.Contains("Rockets:")) {
int myRockets;
p = int.TryParse(s.Replace("Rockets:", "").Trim(), out myRockets);
currentMek.rockets = myRockets;
mekRockets.Value = currentMek.rockets;
}
}
如果我删除或注释掉最后两个 if else,一切都很好。这是为什么呢?
【问题讨论】:
-
在哪一行抛出错误?
-
它在我构建项目时作为异常抛出,但 Xamarin 没有告诉我具体在哪里或具体是什么。只要 if 语句为空,我已将其追踪到“s.Contains(“Missiles:”)。有时,如果我将字符串“Missiles:”更改为其他内容,例如“Miss”,它会起作用,但前提是if语句为空。我猜它似乎与mono中的string.Contains和string.Replace方法有关?
-
你试过在没有调试器的情况下运行代码吗?
-
不,我真的没想到。我想您的意思是发布版本而不是调试版本?我会试一试。
-
好吧,发布版本可以工作,但调试不行?这到底是怎么回事?我该如何解决,或者我可以解决它吗?