Reputation: 261
I'm using Forge .NET API 1.3.0
I'm trying to get hubs via API, just like it is described in the example
I know that...
But for some reason the following line fails with RuntimeBinderException:
Hubs hubs = apiInstance.GetHubs(/*filterId, filterExtensionType*/);
The exception message says:
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Unknown Module. Additional information: Cannot implicitly convert type 'Autodesk.Forge.Model.DynamicJsonResponse' to 'Autodesk.Forge.Model.Hubs'
So obviously the method example shows is not valid anymore (?). How should the resulting data to be converted into Hubs type.
Upvotes: 0
Views: 309
Reputation: 109
This happened to me as well. I solved it using Json Deserializer.
string token = "a token";
var apiInstance = new HubsApi();
apiInstance.Configuration.AccessToken = token;
// Get Hub
dynamic hubsJson = apiInstance.GetHubs();
Hubs allHubs = JsonConvert.DeserializeObject<Hubs>(hubsJson.ToString());
Now the json object is converted to the Forge Api Hubs class.
Upvotes: 0
Reputation: 261
OK, I managed to get it working by using the raw data. Following an example:
var hubs = await hubsApi.GetHubsAsync();
foreach (KeyValuePair<string, dynamic> hubInfo in new DynamicDictionaryItems(hubs.data))
{
new { Id = hubInfo.Value.id, Name = hubInfo.Value.attributes.name }
}
For a reference, following kind of data is inside the "hubs.data" array:
{
"type": "hubs",
"id": "b.aaaaaaaa-bbbb-cccc-1111-222223333333",
"attributes": {
"name": "The hub",
"extension": {
"type": "hubs:autodesk.bim360:Account",
"version": "1.0",
"schema": {
"href": "https://developer.api.autodesk.com/schema/v1/versions/hubs:autodesk.bim360:Account-1.0"
},
"data": {}
}
},
"links": {
"self": {
"href": "https://developer.api.autodesk.com/project/v1/hubs/b.aaaaaaaa-bbbb-cccc-1111-222223333333"
}
},
"relationships": {
"projects": {
"links": {
"related": {
"href": "https://developer.api.autodesk.com/project/v1/hubs/b.aaaaaaaa-bbbb-cccc-1111-222223333333/projects"
}
}
}
}
}
Upvotes: 1
Reputation: 8604
The .NET tutorial shows how to list hubs, you can also download the ready-to-use sample, the DataManagementController
code shows it in action, see here.
Upvotes: 0