Unity still references file moved to different folder

I have this file called GameData.cs and I moved it from top level folder Assets.Scripts to Assets.Scripts.GameDataScripts.
Just to mention I first made folder GameData which clashed with GameData.cs, then I renamed it to GameDataScripts.

I wrote this unit test to test if my function is loading the local disk file but it throws an error:

[Test]
[Category(Helper.TEST_CATEGORY_SAVE_GAME_STATE)]
public void FileDataTest_ ()
{
	// arrange
	var slgdController = FakeSaveLoadGameDataController();
	BinaryFormatter bf = new BinaryFormatter();
	FileStream fs = File.Open(Application.persistentDataPath + Helper.GAME_DATA_FILE_NAME, FileMode.Open);
		// act
	GameData expected = (GameData)bf.Deserialize(fs);
	GameData actual = slgdController.FileData();
	
	// assert
	Assert.AreEqual(expected, actual);
				
	// clean
	fs.Close();
}

Error:

System.TypeLoadException : Could not load type 'Assets.Scripts.GameData'.

As if it is still referencing the the old GameData folder or file GameData.cs

What can I do to tell Unity3D to clear old file/folder references?

Your information here seems to be quite confusing. You talk about a “file” called “GameData.cs”. The extension “.cs” would tell us this is a C# script, right? However all your code seems to just use the class “GameData” that is most likely defined in that script file to deserialize (most likely another) file which should represent an instance of that class.

You said you “moved” the script file. Did you move it inside Unity? Or did you move it in the explorer / finder or any other program? If you moved it outside of Unity, Unity will loose the asset connection to the script unless you moved the “.meta” file along. You should move assets only inside of Unity.

Next thing is the error message:

System.TypeLoadException : Could not load type 'Assets.Scripts.GameData'.

doesn’t reference a certain file, but your class name. You most likely have your GameData class declared in the namespace “Assets.Scripts”. If you created the class in VisualStudio, that’s what usually happens as VS places new classes in a namespace according to their folder names. Moving the file won’t change the namespace.

If you changed the namespace yourself, that would mean you now using a completely different type. The BinaryFormatter stores the exact class type which includes the namespace and the assembly that contains the class. Just because a class has the same name as another class, doesn’t mean it’s the same class if they belong to different namespaces. Best examples are: System.Object and UnityEngine.Object or System.Random and UnityEngine.Random.

Whenever you change anything on your class that you serialize / deserialize with the BinaryFormatter, it will break any serialized data you’ve created already.

So make sure you place your classes in the final namespace you actually want to use before using the class for any serialization. Also keep in mind when adding / removing variables it will break the deserialization as well.