C# Adding Items to list in Foreach not working

I am trying to add items to a list with a foreach method as shown below

foreach (string posi in roomObj.GetComponent<Room>().positions)
			{
				if (posi != "right") //right is occupied
				{
					tempList.Add(new Position(roomObj.GetComponent<Room>(), posi));
					Debug.Log(tempList.Count);
				}
			}
			availablePositions.AddRange(tempList);
			availablePositions.Remove(pos);

The problem is that no matter what I try to do to fix this, I can’t get the tempList.Add to work and it appears as though Unity doesn’t even execute this code as I can’t get the Debug.Log doesn’t show.
What am I doing wrong?

I’d guess that your GetComponent call is not returning anything, and you therefore don’t have anything to foreach through…