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 8814623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:10:28+00:00 2026-06-14T04:10:28+00:00

Is it possible to deserialize part of a binary file? Basically I have an

  • 0

Is it possible to deserialize part of a binary file?

Basically I have an object similar to below, which I serialize into a binary file.

public class MyObject
{
    public string Name { get; set; }

    public int Value { get; set; }

    public IList<MyOtherObject> { get; set; } // lots of data in here (order of kB-MB)
}

What I would like is to be able to deserialize only Name and Value by way of populating a ListView for file selection purposes and then deserialize the rest of the file when needed (i.e. the user chooses that file from the ListView).

As always, any help greatly appreciated and if any 3rd party libraries are suggested they would need to be able to be used freely in a commercial environment.

  • 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-14T04:10:29+00:00Added an answer on June 14, 2026 at 4:10 am

    protobuf-net can do that, because it is not tied to the specific type; for example:

    using ProtoBuf;
    using System.Collections.Generic;
    using System.IO;
    
    [ProtoContract]
    public class MyOtherObject { }
    [ProtoContract]
    public class MyObject
    {
        [ProtoMember(1)]
        public string Name { get; set; }
        [ProtoMember(2)]
        public int Value { get; set; }
        [ProtoMember(3)]
        public IList<MyOtherObject> Items { get; set; }
    }
    
    [ProtoContract]
    public class MyObjectLite
    {
        [ProtoMember(1)]
        public string Name { get; set; }
        [ProtoMember(2)]
        public int Value { get; set; }
    }
    
    static class Program
    {
        static void Main()
        {
            var obj = new MyObject
            {
                Name = "abc",
                Value = 123,
                Items = new List<MyOtherObject>
                {
                    new MyOtherObject(),
                    new MyOtherObject(),
                    new MyOtherObject(),
                    new MyOtherObject(),
                }
            };
            using (var file = File.Create("foo.bin"))
            {
                Serializer.Serialize(file, obj);
            }
            MyObjectLite lite;
            using (var file = File.OpenRead("foo.bin"))
            {
                lite= Serializer.Deserialize<MyObjectLite>(file);
            }
        }
    }
    

    But if you don’t want two different types, and/or you don’t want to have to add attributes – that can be done too:

    using ProtoBuf.Meta;
    using System.Collections.Generic;
    using System.IO;
    
    public class MyOtherObject { }
    public class MyObject
    {
        public string Name { get; set; }
        public int Value { get; set; }
        public IList<MyOtherObject> Items { get; set; }
    }
    static class Program
    {
        static readonly RuntimeTypeModel fatModel, liteModel;
        static Program()
        {
            // configure models
            fatModel = TypeModel.Create();
            fatModel.Add(typeof(MyOtherObject), false);
            fatModel.Add(typeof(MyObject), false).Add("Name", "Value", "Items");
            liteModel = TypeModel.Create();
            liteModel.Add(typeof(MyOtherObject), false);
            liteModel.Add(typeof(MyObject), false).Add("Name", "Value");
        }
        static void Main()
        {
            var obj = new MyObject
            {
                Name = "abc",
                Value = 123,
                Items = new List<MyOtherObject>
                {
                    new MyOtherObject(),
                    new MyOtherObject(),
                    new MyOtherObject(),
                    new MyOtherObject(),
                }
            };
            using (var file = File.Create("foo.bin"))
            {
                fatModel.Serialize(file, obj);
            }
            MyObject lite;
            using (var file = File.OpenRead("foo.bin"))
            {
                lite = (MyObject)liteModel.Deserialize(
                    file, null, typeof(MyObject));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project I have a class which I Serialize in Binary format to
Is it possible to serialize or deserialize any pointer? Suppose I have a class
Is it possible to Deserialize the following piece of XML into a Dictionary<int,string> object?
Possible Duplicate: How to Deserialize XML document Suppose that I have a class that
is it possible to deserialize enums, which have a one based index? enum Status
Is it possible to deserialize an XML file to a class in Flex without
Is it possible to Serialize a class in C++ and deserialize it to a
I am using two methods below to serialize/deserialize entity framework object (ver. 4.0). I
Is it possible to deserialize this XML into an object marked with the DataContract
Is it possible to serialize and deserialize a std::function , a function object, or

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.