Object reference not set to an instance of an object.

This is an error occurred  in the devlopment of a Grasshopper Plugin, when using following code:

protected override void SolveInstance(IGH_DataAccess DA)
string searchFor = “%”;

GH_String pattern = null;
DA.GetData<GH_String>(0, ref pattern);

GH_Number thickness = null;
DA.GetData<GH_Number>(1, ref thickness);

GH_String type = null;
DA.GetData<GH_String>(2, ref type);

GH_String strNew = null;

strNew.Value = pattern.Value.Replace(searchFor, thickness.Value.ToString());

// output has two fields, one new string and the type name

List<GH_String> output = new List<GH_String>();


DA.SetData(0, output);


David Rutten explained the question in the discussion:  http://www.grasshopper3d.com/forum/topics/error-object-reference-not-set-to-an-instance-of-an-object-1

“Object reference not set to an instance of an object” is the most common exception in .NET as far as I know. It means you’re trying to call a method on a class which doesn’t exist. Or rather, a class which hasn’t been instantiated.

Leave a Reply

Your email address will not be published. Required fields are marked *