Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Protobuf.net偶尔出现异常-检查元数据时超时_C#_Protobuf Net - Fatal编程技术网

C# Protobuf.net偶尔出现异常-检查元数据时超时

C# Protobuf.net偶尔出现异常-检查元数据时超时,c#,protobuf-net,C#,Protobuf Net,在少数情况下,我在检查元数据异常时超时。 我只在服务器RAM为95%,CPU超过70%的情况下见过它,即使这样也不可能重现它。此外,仅在序列化列表实例时报告,其中OrderLine为: [Serializable, ProtoContract] public class OrderLine { public OrderLine() { } [ProtoMember(1)] public decimal ID { get; set; } [ProtoMembe

在少数情况下,我在检查元数据异常时超时。 我只在服务器RAM为95%,CPU超过70%的情况下见过它,即使这样也不可能重现它。此外,仅在序列化列表实例时报告,其中OrderLine为:

[Serializable, ProtoContract]
public class OrderLine {

    public OrderLine() { }

    [ProtoMember(1)]
    public decimal ID { get; set; }

    [ProtoMember(2)]
    public string Text { get; set; }

    [ProtoMember(3)]
    public double Qty { get; set; }

    [ProtoMember(4)]
    public DateTime When { get; set; }

    [ProtoMember(5)]
    public OrderTypes OrderType { get; set; }
}
OrderTypes是一个枚举

我正在使用protobuf net将.net实例序列化并稍后持久化到SQLServer数据库。它是通过几个线程并行工作异步完成的

我在这里读到,在启动时预编译序列化程序有助于或避免此异常。以下是启动时运行的一个简短片段:

    static object mysync = new object();
    static ProtoBuf.Meta.RuntimeTypeModel protobufmodel = null;
    ...
    lock (mysync) {
        var pbtypes = new Type[] {
            ... several other types but no Orderline ...
            typeof(List<OrderLine>),
        };
        protobufmodel = ProtoBuf.Meta.TypeModel.Create();
        pbtypes.Select(t => protobufmodel.Add(t, true));
        protobufmodel.CompileInPlace();
    }

我的问题:我是否也应该将类型OrderLine添加到模型中,即添加到pbtypes数组中?那会有帮助吗?或者CompileInPlace有列表就足够了吗?

您意识到了。除非您迭代它,否则Select实际上不会做任何事情,对吧?啊。不间断电源。我真丢脸。就这样。我正在迭代它,但是在调用CompileInPlace之后!我可能在没有注意到我把代码搞砸的情况下重新整理了代码。