I'm making a noughts and crosses game in C# (WPF). This section of code is part of what happens after a player chooses a square to put their next piece in - it uses a method to convert the square's coordinates into a single integer which it can compare to each Image's Tag (1-9) to find the correct Image, which it then changes the Source of. Images, Sources and Tags are WPF-specific but all that is important to this problem is that I have a list of Images, each of which has a Tag, which is an object.
int coordNumber = ReturnNumber(coordinates); //get integer version of coordinates, equivalent to clickedSquare
string coordString = coordNumber.ToString();
object coordObject = coordString;
SquareImages.First(image => image.Tag == coordObject).Source = new ImageSourceConverter().ConvertFromString("Data/Images/Cross.png") as ImageSource;
The .Source
part of the last line is not relevant as it happens after the error. The second and third lines are an attempt to see if casting different ways will change whether it can find an Image with the right Tag, but so far hasn't led to any changes. Two lines have been removed but did not affect the List or shown variables in any way.