Instantiate Returning null

Here is the code:

using UnityEngine;
using System.Collections;

public class BuildManager : MonoBehaviour {

	public Transform CurrentPartPrefab;
	private GameObject CurrentPart;

	private bool haveObject = false;
	private Vector3 mouseWorldPostion;

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		mouseWorldPostion = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		mouseWorldPostion.z = 0;

			if(haveObject == false)

				CurrentPart = Instantiate(CurrentPartPrefab, mouseWorldPostion , gameObject.transform.rotation) as GameObject;
				haveObject = true;

				//CurrentPart.transform.position = mouseWorldPostion;


but CurrentPart even after the instantiate is called is null? I have tried casting it this way:

CurrentPart = (GameObject)Instantiate(CurrentPartPrefab, mouseWorldPostion , gameObject.transform.rotation);

It just trows a runtime error. Does an one know what is wrong here?

Your CurrentPartPrefab is a Transform, you have to cast to Transform instead of GameObject.