Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:26:53+00:00 2026-06-01T14:26:53+00:00

I am rx this error on Deserialization: Invalid wire-type; this usually means you have

  • 0

I am rx this error on Deserialization:

Invalid wire-type; this usually means you have over-written a file without truncating or setting the length; see Using Protobuf-net, I suddenly got an exception about an unknown wire-type

That only mentions File truncation, but I am creating a new file

 Stopwatch sw = new Stopwatch();
            List<SomeClass> items = CreateSomeClass();
            sw.Start();
            using (var file = File.Create(fileName))
            {
                var model = CreateModel();
                model.Serialize(file, items);
                file.SetLength(file.Position);
            }
            sw.Stop();
            logger.Debug("Saving/serialization to {0} took {1} m/s", fileName, sw.ElapsedMilliseconds);
            sw.Reset();
            logger.Debug("Starting deserialzation...");
            sw.Start();
            using (var returnStream = new FileStream(fileName, FileMode.Open))
            {
                var model = CreateModel();
                var deserialized = model.Deserialize(returnStream, null, typeof(SomeClass));
            }
            logger.Debug("Retrieving/deserialization of {0} took {1} m/s", fileName, sw.ElapsedMilliseconds);

 public static TypeModel CreateModel()
    {
        RuntimeTypeModel model = TypeModel.Create();

        model.Add(typeof(SomeClass), false)
            .Add(1, "SomeClassId")
            .Add(2, "FEnum")
            .Add(3, "AEnum")
            .Add(4, "Thing")
            .Add(5, "FirstAmount")
            .Add(6, "SecondAmount")
            .Add(7, "SomeDate");
        TypeModel compiled = model.Compile();

        return compiled;
    }

 public enum FirstEnum
{ 
    First = 0,
    Second,
    Third
}
public enum AnotherEnum
{ 
    AE1 = 0,
    AE2,
    AE3
}
[Serializable()]
public class SomeClass
{
    public int SomeClassId { get; set; }
    public FirstEnum FEnum { get; set; }
    public AnotherEnum AEnum { get; set; }
    string thing;
    public string Thing
    {
        get{return thing;}
        set
        {
            if (string.IsNullOrEmpty(value))
                throw new ArgumentNullException("Thing");

            thing = value;
        }
    }
    public decimal FirstAmount { get; set; }
    public decimal SecondAmount { get; set; }
    public decimal ThirdAmount { get { return FirstAmount - SecondAmount; } }
    public DateTime? SomeDate { get; set; }
}

I am new to Protobuf-net so is there anything obvious I am doing wrong/missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:26:55+00:00Added an answer on June 1, 2026 at 2:26 pm

    You are serializing it as a list, and deserializing it asa single item. This is a problem. Either use DeserializeItems, or: instead of

    typeof(SomeClass)
    

    Pass

    typeof(List<SomeClass>)
    

    The DeserializeItems is probably slightly faster (for various reasons, it has to do extra work when Deserialize is called with a list type as the operand).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This error come in log. from='kutbi1@360degree/Smack' to='akash@360degree/Smack' type='error' id='hK1L6-5'> <si xmlns='http://jabber.org/protocol/si' id='jsi_191216212994140179' mime-type='image/png' profile='http://jabber.org/protocol/si/profile/file-transfer'>
I have this error message: Msg 8134, Level 16, State 1, Line 1 Divide
I'm having troubles with the deserialization of a Json: I get this error: No-args
I have somewhat deep Json structure like below incoming over the wire into C#
this error is always fired, when i'm try to free my allocated struct the
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
Got this error on a big $_GET query in size ~9 000 symbols (they
Getting this error when try to add an item to my repositories/context: Collection has
Got this error message while trying to configure an entitydatasource in the designer: My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.