Protobuf-net “找不到二进制的无参数构造函数”

本文关键字:参数 构造函数 找不到 二进制 Protobuf-net | 更新日期: 2023-09-27 18:30:39

我有一个类是下面的

 [DataContract(IsReference = true)]
    [ProtoContract(SkipConstructor = true)]
    public class BelgeDosyasi : TablesBase
    {
        public BelgeDosyasi()
        {

        }
        [DataMember(Order = 1)]
        public Binary HizmetBelgeDosya { get; set; }
        [DataMember(Order = 2)]
        public string HizmetBelgeUzantisi { get; set; }
        [DataMember(Order = 3)]
        public int HizmetBelgeBoyutu { get; set; }
        [DataMember(Order = 4)]
        public string HizmetBelgeAdi { get; set; }
    }

此类有助于从数据库下载二进制文件,没有 protobuf,它工作得很好,但在对象反序列化开始使用 protobuf 后,我收到此错误"找不到二进制的无参数构造函数"并且无法解决问题。我的protobuf-net版本是版本=2.0.0.668。任何帮助不胜感激。

    at ProtoBuf.Meta.TypeModel.ThrowCannotCreateInstance(Type type) in c:'Dev'protobuf-net'protobuf-net'Meta'TypeModel.cs:line 1397
   at proto_8(Object , ProtoReader )
   at ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read(Object value, ProtoReader source) in c:'Dev'protobuf-net'protobuf-net'Serializers'CompiledSerializer.cs:line 57
   at ProtoBuf.Meta.RuntimeTypeModel.Deserialize(Int32 key, Object value, ProtoReader source) in c:'Dev'protobuf-net'protobuf-net'Meta'RuntimeTypeModel.cs:line 775
   at ProtoBuf.ProtoReader.ReadTypedObject(Object value, Int32 key, ProtoReader reader, Type type) in c:'Dev'protobuf-net'protobuf-net'ProtoReader.cs:line 579
   at ProtoBuf.ProtoReader.ReadObject(Object value, Int32 key, ProtoReader reader) in c:'Dev'protobuf-net'protobuf-net'ProtoReader.cs:line 566
   at proto_6(Object , ProtoReader )
   at ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read(Object value, ProtoReader source) in c:'Dev'protobuf-net'protobuf-net'Serializers'CompiledSerializer.cs:line 57
   at ProtoBuf.Meta.RuntimeTypeModel.Deserialize(Int32 key, Object value, ProtoReader source) in c:'Dev'protobuf-net'protobuf-net'Meta'RuntimeTypeModel.cs:line 775
   at ProtoBuf.ServiceModel.XmlProtoSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName) in c:'Dev'protobuf-net'protobuf-net'ServiceModel'XmlProtoSerializer.cs:line 193
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.PartInfo.ReadObject(XmlDictionaryReader reader, XmlObjectSerializer serializer)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameter(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
   at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

at ProtoBuf.Meta.TypeModel.ThrowCannotCreateInstance(Type type) in c:'Dev'protobuf-net'protobuf-net'Meta'TypeModel.cs:line 1397
   at proto_8(Object , ProtoReader )
   at ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read(Object value, ProtoReader source) in c:'Dev'protobuf-net'protobuf-net'Serializers'CompiledSerializer.cs:line 57
   at ProtoBuf.Meta.RuntimeTypeModel.Deserialize(Int32 key, Object value, ProtoReader source) in c:'Dev'protobuf-net'protobuf-net'Meta'RuntimeTypeModel.cs:line 775
   at ProtoBuf.ProtoReader.ReadTypedObject(Object value, Int32 key, ProtoReader reader, Type type) in c:'Dev'protobuf-net'protobuf-net'ProtoReader.cs:line 579
   at ProtoBuf.ProtoReader.ReadObject(Object value, Int32 key, ProtoReader reader) in c:'Dev'protobuf-net'protobuf-net'ProtoReader.cs:line 566
   at proto_6(Object , ProtoReader )
   at ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read(Object value, ProtoReader source) in c:'Dev'protobuf-net'protobuf-net'Serializers'CompiledSerializer.cs:line 57
   at ProtoBuf.Meta.RuntimeTypeModel.Deserialize(Int32 key, Object value, ProtoReader source) in c:'Dev'protobuf-net'protobuf-net'Meta'RuntimeTypeModel.cs:line 775
   at ProtoBuf.ServiceModel.XmlProtoSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName) in c:'Dev'protobuf-net'protobuf-net'ServiceModel'XmlProtoSerializer.cs:line 193
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.PartInfo.ReadObject(XmlDictionaryReader reader, XmlObjectSerializer serializer)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameter(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
   at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Protobuf-net “找不到二进制的无参数构造函数”

Marc,非常感谢您的回复,是的,我发现例外来自它自己的二进制类型,它是从 Linq.Binary 继承的 av 类型。将其转换为 Byte[] 解决了这个问题。