.NET SDK problem writing object

Hi,

Thanks a lot for your explanation.
I just tried the .NET SDK and I am able to read objects and create new objects.

To understand Speckle I tried a couple of different things.

For example: I created an Base Object contains two lines:

var myBuilding = new Base();
myBuilding["name"] = "Test";
myBuilding["line1"] = new Line(new Point(0,0,0), new Point(10,10,10));
myBuilding["line2"] = new Line(new Point(0,0,0), new Point(0,0,10));
var commitId = Helpers.Send(streamId, myBuilding, "My commit message").Result;

As expected I can see the new commit with my two lines.

With the following code I read the referenceObject ID and afterwards the complete referenceObject

var branchName = "main";
var client = new Client(account);
var branch = await client.BranchGet(streamId, branchName, 1);
var objectId = branch.commits.items[0].referencedObject; // 

 var transport = new ServerTransport(account, streamId);
 var data1 = await Operations.Receive(
     objectId,
     remoteTransport: transport
 );

As you can see I am able to read the object.

I have the following guestions:

  1. Why is totalChidrenCount =0 not 3 (two lines and the name)?
  2. Why is the line1 one and line2 from Object Base, not from Line?
  3. If I try to read the line1 object I recive the following error:
[18:44:35 ERR] A deserialization error has occurred Cannot deserialize objectJson, value was null (Parameter 'objectJson')
System.ArgumentNullException: Cannot deserialize objectJson, value was null (Parameter 'objectJson')
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.DeserializeTransportObject(String objectJson)
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.Deserialize(String rootObjectJson)
   at Speckle.Core.Api.Operations.DeserializeStringToBase(SerializerVersion serializerVersion, String objString, JsonSerializerSettings settings, BaseObjectDeserializerV2 serializerV2)
Unhandled exception. System.ArgumentNullException: Cannot deserialize objectJson, value was null (Parameter 'objectJson')
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.DeserializeTransportObject(String objectJson)
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.Deserialize(String rootObjectJson)
   at Speckle.Core.Api.Operations.DeserializeStringToBase(SerializerVersion serializerVersion, String objString, JsonSerializerSettings settings, BaseObjectDeserializerV2 serializerV2)
   at Speckle.Core.Api.Operations.Receive(String objectId, CancellationToken cancellationToken, ITransport remoteTransport, ITransport localTransport, Action`1 onProgressAction, Action`2 onErrorAction, Action`1 onTotalChildrenCountKnown, Boolean disposeTransports, SerializerVersion serializerVersion)
  1. In the Speckle backend I can see my two lines, but if I click on the “Open object in a new window I receive the 404 error

What did I miss?

Furthermore I would like to know how I can add a new property to an existing object.
In the documentation it is mentioned that objects are immutable. For example I would like to add one the line1 object the attribute name.
Is it enough to commit only the line1 object, or is it necessary to commit the whole object?

Thanks a lot
Ludi

I have same problem before, and just quick update and update count manual when you send data :

RoomData roomData = new RoomData()
      {
          Parameters = data,
          Name = element.Name,
          ElementId = element.Id.IntegerValue,
          Lines = lines,
      };
      Rooms.Add(roomData);
  }
commitObject["Rooms"] = Rooms;
string resultCommit = client.CommitCreate(
            new CommitCreateInput
            {
                streamId = streamId,
                branchName = branch.name,
                objectId = id,
                message = "Revit Element Room",
                totalChildrenCount = Rooms.Count,
            }).Result;
ServerTransportV2 serverTransportV2 = new ServerTransport(defaultAccount, streamId);
string id = Operations.Send(commitObject, new List<ITransport>() {serverTransportV2}).Result;

I updated totalChildrenCount by hand and after reading the property is set correctly.

But I still get the following error after clicking on a line and “Open object in a new window"

The reason why your line objects are not found when opening in a new window, is because they are not detached objects.

You can read more about what detaching is here: The Base Object | Speckle Docs
But detaching is a requirement in order to have a separate queryable object, and it is recommended to detach geometry objects.

You can easily do so through modifying your code to use the @ prefix on property names. i.e.

var myBuilding = new Base();
    myBuilding["name"] = "Test";
    myBuilding["@line1"] = new Line(new Point(0,0,0), new Point(10,10,10));
    myBuilding["@line2"] = new Line(new Point(0,0,0), new Point(0,0,10));
    var commitId = Helpers.Send(streamId, myBuilding, "My commit message").Result;

If you’re curious what difference it makes to the JSON objects, you can query for the raw json through https://speckle.xyz/explorer

Here is a query for the root commit object before detaching. You can see the root object has the data for the Line1 (and below screen is line 2 also)

Whereas, if we detach Line1 and Line2 you get this.


The root object now contains references to line 1 and 2, and we can also now query for them.
And because they are queryable, they also available at the {server_url}/stream/{stream_id}/objects/{object_id} endpoint.

et voila: Speckle

1 Like

Hi @Jedd,

Thank you very much for your explanation. That was very helpful :wink:

All my tests are successful, except one.
I importet an IFC file (project1-wp-2-2-bim/IFC_Files/MISC/AC20-FZK-Haus.ifc at 90ad1ed2fd1f84643ca866ceda5667cb0d0274f9 · ibpsa/project1-wp-2-2-bim · GitHub ) and tried to load the ifc file with the sdk.

I used the following line:

 var data = Helpers.Receive(streamIdHouse).Result;

I receive the following error:

...
[14:32:40 ERR] A deserialization error has occurred Cannot deserialize System.Double to System.Int32
System.Exception: Cannot deserialize System.Double to System.Int32
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.Dict2Base(Dictionary`2 dictObj)
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.ConvertJsonElement(JToken doc)
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.ConvertJsonElement(JToken doc)
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.DeserializeTransportObject(String objectJson)
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.DeserializeTransportObjectProxy(String objectJson)
   at Speckle.Core.Serialisation.BaseObjectDeserializerV2.Deserialize(String rootObjectJson)
   at Speckle.Core.Api.Operations.DeserializeStringToBase(SerializerVersion serializerVersion, String objString, JsonSerializerSettings settings, BaseObjectDeserializerV2 serializerV2)

Is there a problem in the SDK?

Thanks a lot
Ludi

Looks like this is an issue with our IFC import service. Some of the RenderMaterials are coming in with invalid (non int32) diffuse values.

There is an open issue tracked for this on github. IFC Serialization Issues · Issue #1625 · specklesystems/speckle-server · GitHub