首页 > 解决方案 > 使用 xbim 创建字符串 IfcParameterValue 会导致异常

问题描述

我正在尝试使用 c# 中的 xbim (v5.1.323) 将字符串 IfcParameterValue 添加到现有的 IfcFlowSegment (Ifc2x3),在下面的代码中称为“圆柱体”。“IfcParameterValue”的构造函数接受双精度和字符串。添加一个双精度值效果很好,但是在尝试通过将字符串传递给构造函数来创建 IfcParameterValue 时,我总是遇到错误。

工作(双值)

IfcValue value = new IfcParameterValue(33d);
cylinder.SetPropertySingleValue("MySet", "Value 1", value);

不工作(字符串值)

IfcValue valueString = new IfcParameterValue("myStringValue"); // Exception!!!
cylinder.SetPropertySingleValue("MySet", "Value 2", valueString);

这是我得到的错误:

System.NotSupportedException:不支持“System.Type”实例的序列化和反序列化,应该避免,因为它们会导致安全问题。路径:$.TargetSite.DeclaringType。---> System.NotSupportedException:不支持“System.Type”实例的序列化和反序列化,应该避免,因为它们会导致安全问题。在 System.Text.Json.Serialization.Converters.TypeConverter.Write(Utf8JsonWriter writer, Type value, JsonSerializerOptions options) 在 System.Text.Json.Serialization.JsonConverter 1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.JsonPropertyInfo1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer) 在 System. Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.JsonPropertyInfo 1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter 1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)

知道什么可能导致此异常吗?或者您是否有更好的解决方案可以轻松地将参数(属性)添加到 IfcElement?

非常感谢!

标签: c#xbim

解决方案


推荐阅读