简体   繁体   English

Forge .NET API RuntimeBinderException

[英]Forge .NET API RuntimeBinderException

I'm using Forge .NET API 1.3.0我正在使用 Forge .NET API 1.3.0

I'm trying to get hubs via API, just like it is described in the example我正在尝试通过 API 获取集线器,就像示例中描述的那样

I know that...我知道...

  • My authentication works我的身份验证有效
  • Query results correct data查询结果正确数据

But for some reason the following line fails with RuntimeBinderException:但由于某种原因,以下行因 RuntimeBinderException 而失败:

Hubs hubs = apiInstance.GetHubs(/*filterId, filterExtensionType*/);

The exception message says:异常消息说:

Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Unknown Module.抛出异常:未知模块中的“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”。 Additional information: Cannot implicitly convert type 'Autodesk.Forge.Model.DynamicJsonResponse' to 'Autodesk.Forge.Model.Hubs'附加信息:无法将类型“Autodesk.Forge.Model.DynamicJsonResponse”隐式转换为“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.生成的数据应该如何转换为 Hubs 类型。

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:作为参考,以下类型的数据位于“hubs.data”数组中:

{
"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"
            }
        }
    }
}

} }

.NET 教程展示了如何列出集线器,您还可以下载即用型示例DataManagementController代码显示了它的实际效果, 请参见此处

This happened to me as well.这也发生在我身上。 I solved it using Json Deserializer.我使用 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.现在 json 对象转换为 Forge Api Hubs 类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM