WHAT TO DO? ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.

THERE IS A MISTAKE:
ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
0

XmlDocument xmlDoc = new XmlDocument();
    			string filepath = Application.dataPath + @"/models/object_list_test.xml";
    			xmlDoc.Load(filepath);
    
    			//string newValue = string.Empty;
    			XmlNode node = xmlDoc.SelectSingleNode("ArrayOfModelImportInfo/ModelImportInfo/path");
    			node.Attributes[0].Value = qaz;
    
    			xmlDoc.Save(filepath);

Check the following things:

  • is node valid, meaning != null?

  • is node.Attributes valid, meaning != null?

  • does node.Attributes have any elements, meaning node.Attributes.Count > 0 (or node.Attributes.Length > 0 if Attributes is an array)?

In your case, the last one is the problem.

If any of these conditions is not met, you will get some error. Remember, always check the validity of your reference types, and the size of your collections before indexing into them!