Can't convert instantiated object to GameObject?

For some reason, I can’t seem to save an instantiated object to a GameObject. My code looks like:

	public GameObject weaponPrefab;
	
	BoneHelper boneHelper;
	Transform weapon;
	
	// Use this for initialization
	void Start () {
		boneHelper = GetComponent<BoneHelper>();
		boneHelper.Init();
		
		GameObject weaponObj = (GameObject)Instantiate(weaponPrefab);
		
		print("Weapon Obj: " + weaponObj);
		
		weapon = weaponObj.transform;
		
		Transform rightHandBone = boneHelper.GetBone("hand.r");
		if(rightHandBone != null)
		{
			weapon.parent = rightHandBone;
		}else
		{
			print("Could not fine bone 'hand.r'");
		}
	}

The error “Cannot cast from source type to destination type” happens at the Instantiate line. If I use ‘as’ instead of the more common cast syntax, the weaponObj print out looks like "Weapon Obj: " with no object being shown and the next line will give a null pointer error.

I’ve never had this problem before and I’m pretty sure it should work. Anyone have any idea why it’s complaining?

I’m not really sure what the problem was, but I noticed that the prefab that had this script attached to it was showing Type Mismatch on the weaponPrefab param. I dragged the same prefab I had before onto the arg and tried again, but this time got no error.

I did have some compile time errors while writing this script. My best guess is that something didn’t clean correctly when rebuilding, after I fixed the errors, and that caused the issue.