When I try to create a CommonObject (Material Rhino 7) instance from a JSON string I get the following error:
Unhandled exception. System.Runtime.Serialization.SerializationException: Unable to read CommonObject from base64 encoded string
This error occurs with a json string of type Material. It does work with a brep or layer json string.
Below is a sample code:
//Material to json string (Is working)
Material dummyMaterial = new Material();
string materialAsJson = dummyMaterial.ToJSON(null);
Console.WriteLine(materialAsJson);
//JsonMaterial back to CommonObject (Material) (NOT WORKING)
CommonObject materialFromJson = CommonObject.FromJSON(materialAsJson);
// = Unhandled exception. System.Runtime.Serialization.SerializationException: Unable to read CommonObject from base64 encoded string
//Brep to json and back (Is working)
Brep dummyBrep = new Brep();
string brepAsJson = dummyBrep.ToJSON(null);
Console.WriteLine(brepAsJson);
CommonObject brepFromJson = CommonObject.FromJSON(brepAsJson);
//Layer to json and back (Is working)
Layer dummyLayer = new Layer();
string layerAsSjon = dummyLayer.ToJSON(null);
Console.WriteLine(layerAsSjon);
CommonObject layerFromJson = CommonObject.FromJSON(layerAsSjon);
Does anyone know why Material.FromJSON() doesn’t work and Brep.FromJSON(), Layer.FromJSON() does?
I have tried this code on both Rhino3dm and RhinoCommon, with both assemblies I get the same result.