Cannot cast from source type to destination type

I get that error when I try to run this code:

GameObject x = (GameObject)Instantiate(cube, transform.position, transform.rotation);

The strange thing is, I have the exact same thing in another script, and it runs : /

what is cube? make sure it’s not null… if you’re trying to instantiate a primitive cube (not a prefab named ‘cube’) then you need to use GameObject.CreatePrimitive instead.