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);
Answer by Harinezumi · Jan 31, 2018 at 04:59 PM
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!
Your answer
Follow this Question
Related Questions
Getting Questions and Answers from XML file and applying them to the UI 2 Answers
XML Save transform position 1 Answer
Loading xml on android . Tried and it Works in windows... Help ? 0 Answers
Validation errors when using XmlReader on XML/SVG files with inline DTDs (Unity/Mono C#) 0 Answers
I can't save xml file in iOS project during the runtime! (written by unity/C#) 0 Answers