Note that there are some explanatory texts on larger screens.

plurals
  1. PO“Index was outside the bounds of the array” when run outside of the IDE
    text
    copied!<p>I've just started learning C# and had created this simple configuration file generator for a Minecraft launcher, just as something to do. I'm having trouble when trying to run the application independently from Visual C# 2010 - it spits out <em>"Index and length must refer to a location within the string. Parameter name:length"</em> on first run (when the blank text file is created) and <em>"index was outside the bounds of the array"</em> if I start it again after this.</p> <p>I'm confused as to why this is happening - it isn't giving me any line numbers, and it only happens when I don't run the application through the IDE (whether I run a debug build or release build). Any help is much appreciated. I apologise for my possibly horrible coding - I'm a beginner with this language.</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Minecraft_Launcher_Config { public partial class mcwindow : Form { private void outputText(string outtext) { output.Text = outtext; } private string encrypt(string text, int key) { string newText = ""; for (int i = 0; i &lt; text.Length; i++) { int charValue = Convert.ToInt32(text[i]); charValue ^= key; newText += char.ConvertFromUtf32(charValue); } return newText; } public mcwindow() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string iuser = ""; string ipass = ""; string imem = "1024"; string iserver = ""; if (System.IO.File.Exists("config.cfg")) { System.IO.StreamReader configFile = new System.IO.StreamReader("config.cfg"); string[] iconfig = System.IO.File.ReadAllLines("config.cfg"); iuser = iconfig[0]; ipass = iconfig[1]; imem = iconfig[2]; iserver = iconfig[3]; configFile.Close(); outputText("Successfully loaded and decrypted config!"); } else { System.IO.StreamWriter configwrite = new System.IO.StreamWriter("config.cfg"); configwrite.Close(); outputText("Welcome to Frohman's Minecraft Launcher Config!"); } username.Text = iuser; memselect.Value = int.Parse(imem); int OKey = Convert.ToInt32(username.Text.Substring(0, 1)); string unenpassword = encrypt(ipass, OKey); password.Text = unenpassword; } private void label1_Click(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void saveexit_Click(object sender, EventArgs e) { if (username.Text != "" &amp; password.Text != "") { outputText("Saving and exiting!"); int IKey = Convert.ToInt32(username.Text[0]); string enpassword = encrypt(password.Text, IKey); string outString = username.Text + System.Environment.NewLine + enpassword + System.Environment.NewLine + memselect.Value + System.Environment.NewLine + serverip.Text; System.IO.StreamWriter configwrite = new System.IO.StreamWriter("config.cfg"); configwrite.WriteLine(outString); configwrite.Close(); System.Threading.Thread.Sleep(150); Environment.Exit(0); } else { outputText("You're missing some data!"); } } private void password_TextChanged(object sender, EventArgs e) { } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload